禁用特定包的日志记录
我正在我的应用程序中实现 python 日志记录,并且我希望能够利用“默认”根设置。我想使用根设置,因为我不想在配置文件中为每个模块定义一个记录器。
当我打开根记录器的调试级别日志记录时,我遇到了 QPID Python 客户端 API 的问题。我的日志文件中充斥着 qpid 调试语句:
2011-03-16 09:16:18,664 - qpid.messaging.io.ops - 调试 - 发送[8de6b2c]:..
2011-03-16 09:16:18,667 - qpid.messaging.io.raw - 调试 - ..
2011-03-16 09:16:18,668 - qpid.messaging.io.raw - 调试 - 读取[8de6b2c]:..
2011-03-16 09:16:18,668 - qpid.messaging.io.ops - 调试 - ..
等等..
所以两个主要问题:
1)有没有办法只为我的模块启用*日志记录,而无需为每个模块定义记录器?换句话说,有没有办法进行共享“记录器设置”,因此不必为每个记录器定义 logger_ 部分,有没有办法默认设置?
比如:
[logger_shared_settings]
loggers = logger_A,logger_B,logger_C,logger_D
level=DEBUG
2)或者我如何通过配置文件过滤掉 qpid 包日志记录?
这是 log.conf 文件:
[loggers]
keys=root
[handlers]
keys=consoleHandler,fileHandler,nullHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)
[handler_fileHandler]
class=logging.handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('out.log',)
这是我试图避免的:
[loggers]
keys=root, a, b, c, d
[handlers]
keys=consoleHandler,fileHandler,nullHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=ERROR
handlers=nullHandler
[logger_a]
level=DEBUG
handlers=consoleHandler,fileHandler
[logger_b]
level=DEBUG
handlers=consoleHandler,fileHandler
[logger_c]
level=DEBUG
handlers=consoleHandler,fileHandler
I am implementing python logging in my application, and I want to be able to leverage the "default" root settings. I want to use root settings because I dont want to have to define a logger per module in a config file.
When I turn on DEBUG level logging for the root logger, I am running into an issue with the QPID Python Client API. My log files get flooded with qpid debug statements:
2011-03-16 09:16:18,664 - qpid.messaging.io.ops - DEBUG - SENT[8de6b2c]: ..
2011-03-16 09:16:18,667 - qpid.messaging.io.raw - DEBUG - ..
2011-03-16 09:16:18,668 - qpid.messaging.io.raw - DEBUG - READ[8de6b2c]: ..
2011-03-16 09:16:18,668 - qpid.messaging.io.ops - DEBUG - ..
Etc..
So two main questions:
1) Is there a way to enable* logging for just my modules without defining a logger per module? In other words is there a way to do shared "logger settings," so instead of having to define a logger_ section per logger is there a way to default the settings?
Something like:
[logger_shared_settings]
loggers = logger_A,logger_B,logger_C,logger_D
level=DEBUG
2) Or How can i filter out the qpid package logging via a config file?
Here is the log.conf file:
[loggers]
keys=root
[handlers]
keys=consoleHandler,fileHandler,nullHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)
[handler_fileHandler]
class=logging.handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('out.log',)
Here was what I was trying to avoid:
[loggers]
keys=root, a, b, c, d
[handlers]
keys=consoleHandler,fileHandler,nullHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=ERROR
handlers=nullHandler
[logger_a]
level=DEBUG
handlers=consoleHandler,fileHandler
[logger_b]
level=DEBUG
handlers=consoleHandler,fileHandler
[logger_c]
level=DEBUG
handlers=consoleHandler,fileHandler
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 python2.7,您可以将 NullHandler 设置为 qpid 记录器:
With python2.7 you can set NullHandler to qpid logger: