Disable logging for a particular package
Asked Answered
M

1

7

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
Mistake answered 16/3, 2011 at 13:29 Comment(0)
U
4

With python2.7 you can set NullHandler to qpid logger:

[logger_qpid]
level=NOTSET
handlers=nullHandler
qualname=qpid
propagate=0
Urbanism answered 16/3, 2011 at 14:50 Comment(5)
Hmmm... what means "shared settings"?Urbanism
Kind of like the root logger, but a different section which I could apply the the modules in my application.Mistake
This is impossible because of the hierarchical structure of the loggers, but I guess, that in python2.7 you can try create your own config based on dictConfig feature of logging module.Urbanism
How does adding null handler to child logger prevent root logger from displaying log messages?Peggypegma
handler is required, so it's set to nullHandler, actual works here done by "propagate" param.Urbanism

© 2022 - 2024 — McMap. All rights reserved.