There are three parts to introducing logging into an application:
- Creating logger objects
- Placing log requests near important state changes
- Configuring the logging system as a whole
Creating loggers can be done in a variety of ways. Additionally, it can also be ignored. As a default, we can use the logging module itself as a logger. If we use the logging.info() method, for example, this will implicitly use the root logger.
A more common approach is to create one logger with the same name as the module:
logger = logging.getLogger(__name__)
For the top-level, main script, this will have the name "__main__". For imported modules, the name will match the module name.
In more complex applications, there will be a variety of ...