Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

Dieter Maurer dieter at handshake.de
Wed Jun 22 13:52:03 EDT 2022


Chethan Kumar S wrote at 2022-6-21 02:04 -0700:
> ...
>I have a main process which makes use of different other modules. And these modules also use other modules. I need to log all the logs into single log file. Due to use of TimedRotatingFileHandler, my log behaves differently after midnight. I got to know why it is so but couldn't get how I can solve it.
>Issue was because of serialization in logging when multiple processes are involved.
>
>Below is log_config.py which is used by all other modules to get the logger and log.
>import logging
>import sys
>from logging.handlers import TimedRotatingFileHandler
>
>FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(message)s")

The usual logging usage pattern is:
the individual components decide what to log
but how the logging happens it decided centrally - common
for all components.
This implies that usually the individual components do not handle
handlers or formatters but use the configuration set up centrally.


More information about the Python-list mailing list