logging setLevel, how it works

后端 未结 3 690
遥遥无期
遥遥无期 2020-12-14 05:57

In the logging howto documentation there is this example:

import logging

# create logger
logger = logging.getLogger(\'simple_example\')
logger.setLevel(l         


        
3条回答
  •  悲哀的现实
    2020-12-14 06:53

    Why I should set the level to logging.DEBUG twice, for logger, and for the streamhandler. I understand ch.setLevel(logging.DEBUG) will set the debug level for the stream handler. But what the effect is of setting the level to logger?. Where this level is reflected?.

    This is indicated in the documentation:

    "The setLevel() method, just as in logger objects, specifies the lowest severity that will be dispatched to the appropriate destination. Why are there two setLevel() methods? The level set in the logger determines which severity of messages it will pass to its handlers. The level set in each handler determines which messages that handler will send on."

    Check under Handlers: http://docs.python.org/2.7/howto/logging.html#logging-advanced-tutorial

提交回复
热议问题