Skip to content Skip to sidebar Skip to footer

Python.logging: Why Does My Non-basicconfig Setting Not Work?

I want to log to a single log file from main and all sub modules. The log messages send from a main file, where I define the logger, work as expected. But the ones send from a call

Solution 1:

You need to configure the (one and only) root logger in the main module of your software. This is done by calling

logger = logging.getLogger() #without arguments

instead of

logger = logging.getLogger(__name__)

(Python doc on logging)

The second example creates a separate, child logger with the name of your script.

If there are no handlers defined in the submodules, the log message is being passed down to the root logger to handle it.

A related question can be found here: Python Logging - How to inherit root logger level & handler

Post a Comment for "Python.logging: Why Does My Non-basicconfig Setting Not Work?"