Tuesday, 15 January 2013

Python: setLevel of specific class's logger -


How can I silence class entrance without knowing the name of my logger? Class in question

  import logging import qualysconnect.util # set log option This is my silence logger_qc = logging.getLogger ('qualysconnect') logger_qc.setLevel (logging.ERROR) # a handler which sys Stderr logger_console = logging.StreamHandler writes warning message or higher Define () logger_console.setLevel (logging.ERROR) #set is a format which is easy to use for the console Formatter = logging.Formatter ('% (name) -12s :% (Levelname) -8s% (message) s') # Tell the handler to use this format. Logger_console.setFormatter (Formator) # Add the handler to the root logger logging.getLogger (''). AddHandler (logger_console) # 'Application' code logging.debug ('debug message') logging.info ('information message') logging ('warning message') logging. Terror ('error message') logging.critical ('important message')   

Output when import qualysconnect.util is commented out: < Pre> root: error error message root: critical critical message

output when import qualysconnect.util is placed in:

   getLogger  as a  qualysconnect.util  or a  Getchild do not call , you can not do anything on that which will not affect the logging behavior of the whole module without getting dirty.  

The only clean option I can think of is how to handle it from entering a bug, report, and a patched request where modified is qualysconnect. Access statement with something like: .

  import login logger = logging.getLogger ('qualysconnect') getChild ('use')   

and logging.info () , logging.debug () ... in logger.info () , replace logger. Debug () ...

Dirty options: You can change the monkey patch in the qualysconnect.util module so that you have your logging Replace object with a logger object:

  import qualysconnect.util logger_qc = logging.getLogger ('qualysconnect') logger_qc.setLevel (logging. ERROR) qualysconnect.util.logging = logger_qc .getLogger ('qualysconnect') .get child ('use') qualysconnect.util.logging.disable (logging .crtycol) # will disable for all serious and bottom   

Time can be a working solution This is when you are sending a patch request to the upstream project, but there is definitely no long term solution.

Or you can completely turn off the whole logging qualysconnect module, but I do not think what you want.

No comments:

Post a Comment