使用 Scapy 生成数据包的 PDF 时如何抑制 PyX 警告消息?

How to suppress PyX warning messages when using Scapy to generate a PDF of a packet?

我正在使用 Scapy 的 pdfdump method:

生成数据包的 PDF
from scapy.layers.inet import ICMP, IP

packet = IP(dst="192.168.111.1") / ICMP()
packet.pdfdump("report.pdf")

执行此代码时,会从 PyX 库中打印出大量消息。

PyX executes tex with args ['--output-directory', '/tmp/pyx1ojf7_d9'] located at /usr/bin/tex
PyX filelocator found 10pt.lfs by method internal
PyX executes kpsewhich with args ['--format', 'vf', 'cmss10'] located at /usr/bin/kpsewhich
PyX filelocator failed to find cmss10 of type ('vf',) and extensions {'', '.vf'}
PyX executes kpsewhich with args ['--format', 'tfm', 'cmss10'] located at /usr/bin/kpsewhich
PyX filelocator found cmss10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmss10.tfm
PyX executes kpsewhich with args ['--format', 'vf', 'cmtt10'] located at /usr/bin/kpsewhich
PyX filelocator failed to find cmtt10 of type ('vf',) and extensions {'', '.vf'}
PyX executes kpsewhich with args ['--format', 'tfm', 'cmtt10'] located at /usr/bin/kpsewhich
PyX filelocator found cmtt10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmtt10.tfm
PyX executes kpsewhich with args ['--format', 'map', 'pdftex.map'] located at /usr/bin/kpsewhich
PyX filelocator found pdftex.map by method kpsewhich at /var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map
PyX executes kpsewhich with args ['--format', 'type1 fonts', 'cmss10.pfb'] located at /usr/bin/kpsewhich
PyX filelocator found cmss10.pfb by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmss10.pfb
PyX executes kpsewhich with args ['--format', 'afm', 'cmss10'] located at /usr/bin/kpsewhich
PyX filelocator found cmss10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/afm/public/amsfonts/cm/cmss10.afm
PyX executes kpsewhich with args ['--format', 'type1 fonts', 'cmtt10.pfb'] located at /usr/bin/kpsewhich
PyX filelocator found cmtt10.pfb by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb
PyX executes kpsewhich with args ['--format', 'afm', 'cmtt10'] located at /usr/bin/kpsewhich
PyX filelocator found cmtt10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/afm/public/amsfonts/cm/cmtt10.afm

有没有办法禁用或抑制这些消息,使其不被打印出来? PyX manual 没有太多关于如何调整这些消息的冗长程度的内容。

此输出是使用标准 python 日志记录框架在日志记录级别 logging.INFO 创建的。默认情况下,此类日志输出是静音的,因为默认值为 logging.WARNING (IIRC)。无论如何,只需调整您的日志记录级别以防止通知打扰您。此外,您还可以查看 pyxinfo 调用,这是 PyX 提供的用于启用此输出的解决方案。 (也许这是由您正在使用的库在某处调用的,而您想禁用它。)请注意,PyX 的这种行为也记录在 http://pyx.sourceforge.net/manual/text.html#debugging