Python logging not outputting anything

前端 未结 4 1033
无人及你
无人及你 2021-01-29 21:06

In a python script I am writing, I am trying to log events using the logging module. I have the following code to configure my logger:

ERROR_FORMAT = \"%(levelna         


        
4条回答
  •  醉话见心
    2021-01-29 21:47

    The default logging level is warning. Since you haven't changed the level, the root logger's level is still warning. That means that it will ignore any logging with a level that is lower than warning, including debug loggings.

    This is explained in the tutorial:

    import logging
    logging.warning('Watch out!') # will print a message to the console
    logging.info('I told you so') # will not print anything
    

    The 'info' line doesn't print anything, because the level is higher than info.

    To change the level, just set it in the root logger:

    'root':{'handlers':('console', 'file'), 'level':'DEBUG'}
    

    In other words, it's not enough to define a handler with level=DEBUG, the actual logging level must also be DEBUG in order to get it to output anything.

提交回复
热议问题