Some high level points
- Logging at the highest package level is enough. This automatically takes care of logging all the children packages and modules.
- Different high level modules will need their own loggers.
- Load the config (dict/file) through the main.py file.
Using context manager vs using decorator
Context Manager: Log over arbitrary code lines and can be applied on single or multiple function calls.
Decorator: Works on a per function basis.
Debugging for multiple modules
Define logger per module. Use logger hierarchy to take care of sub-modulesStandardize logging functions and config across modules by using a file config.
Every instance invoked using a unique name is a singleton by default. Multiple calls to logging.getLogger() will return a reference to the same logger object, even across modules.
For logging application code, create an configure a parent logger, but only create the child loggers. The logger calls from the child logger will be propagated to and handled by the parent logger.
The name of the children loggers are automatically configured from the parent logger and there is no need for setting unique names for every piece of application code.
Create the loggers after you load configuration, since disable_existing_loggers is True by default. Otherwise you can override the the order of loading and declaration.