Search code examples
pythonloggingpython-logging

Where is this logging to?


I have this Python code:

import logging
LOGGER = logging.getLogger(__name__)
LOGGER.info('test')

It does not get written to the console, so where does this get logged?


Solution

  • This does not get logged anywhere, because you did not configure any handlers for the logging framework. Without a handler configured, the log event just gets dropped.

    When there aren't any handlers configured, if an event at WARNING or above is seen the root logger will get a handler added automatically, but your event was just at INFO level so that doesn't happen here.

    If you include a line like this beforehand to configure the logging framework, then you will see the INFO event logged to terminal:

    logging.basicConfig(level=logging.INFO)
    

    Using basic config will add a StreamHandler writing to sys.stderr if you don't specify otherwise.