在Python中使用记录模块的奇怪问题

埃里亚斯51

在正在处理的应用程序中调用另一个模块后记录数据时,似乎遇到了问题。我想协助您了解这里可能发生的情况。

为了复制该问题,我开发了以下脚本...

#!/usr/bin/python

import sys
import logging
from oletools.olevba import VBA_Parser, VBA_Scanner
from cloghandler import ConcurrentRotatingFileHandler

# set up logger for application
dbg_h = logging.getLogger('dbg_log')
dbglog = '%s' % 'dbg.log'
dbg_rotateHandler = ConcurrentRotatingFileHandler(dbglog, "a")
dbg_h.addHandler(dbg_rotateHandler)
dbg_h.setLevel(logging.ERROR)

# read some document as a buffer
buff = sys.stdin.read()

# generate issue
dbg_h.error('Before call to module....')
vba = VBA_Parser('None', data=buff)
dbg_h.error('After call to module....')

运行此命令时,我得到以下信息...

cat somedocument.doc | ./replicate.py
ERROR:dbg_log:After call to module....

由于某种原因,我最后一次dbg_h记录器写尝试是要输出到控制台,还是要写到dbg.log文件?这似乎仅在调用VBA_Parser之后发生。

cat dbg.log
Before call to module....
After call to module....

任何人都知道为什么会发生这种情况吗?我查看了olevba源代码,但没有发现任何特别明显的问题。

我应该向模块作者提出这个问题吗?还是我在使用cloghandler时做错了什么?

约翰·珀西瓦尔·哈克沃思(John Percival Hackworth)

oletools代码库充斥着调用根logger虽然来电logging.debug(...)logging.error(...)等。由于作者不必费心配置root记录器,因此默认行为是转储到sys.stderr由于sys.stderr从命令行运行时默认为控制台,因此您将获得所看到的内容。

您应该与作者联系,oletools因为他们没有有效使用日志记录系统。理想情况下,他们将使用命名记录器并将消息推送到该记录器。作为抑制消息的一种解决方法,您可以配置根记录程序以使用您的处理程序。

# Set a handler
logger.root.addHandler(dbg_rotateHandler)

请注意,这可能会导致日志消息重复。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Python中使用CEX API的问题-无法使用模块。

来自分类Dev

Prestashop模块奇怪的问题

来自分类Dev

奇怪的python csv模块行为-不要分割记录

来自分类Dev

Python的psutil模块和一个奇怪的问题

来自分类Dev

在Joomla中使用“滚动文字”模块的问题

来自分类Dev

在 Java 中使用 OpenCV Kurento 模块的问题

来自分类Dev

在python中使用Wikipedia模块

来自分类Dev

在Python中使用“输入”的奇怪错误

来自分类Dev

批次:在Set / p输入中使用空格的奇怪问题

来自分类Dev

当我在Elixir的嵌套模块中使用模块名称时,谁能解释奇怪的结果?

来自分类Dev

使用Python中的日志记录模块进行颜色日志记录

来自分类Dev

使用Python中的日志记录模块进行颜色日志记录

来自分类Dev

使用sys模块的Python 3中的奇怪行为

来自分类Dev

在 RasPi 上使用 psutil(Python 模块)的问题

来自分类Dev

在模块中使用用户表单时遇到问题

来自分类Dev

Python:数组中使用的模拟补丁模块

来自分类Dev

如何在python中使用gfx模块

来自分类Dev

在Python Twisted线程中使用Cmd模块

来自分类Dev

在Python的子流程模块中使用PATH

来自分类Dev

在Vim中使用ctags导航Python模块?

来自分类Dev

在Python 3中使用集合模块

来自分类Dev

在Pypy中使用Python模块[Windows]

来自分类Dev

无法在python中使用gTTS模块

来自分类Dev

在Python Twisted线程中使用Cmd模块

来自分类Dev

在整个模块中使用对象。Python

来自分类Dev

如何在python中使用gfx模块

来自分类Dev

在Vim中使用ctags导航Python模块?

来自分类Dev

Python:数组中使用的Mock Patch模块

来自分类Dev

无法在python模块中使用Stanford NER

Related 相关文章

热门标签

归档