Friday, October 16, 2020

Python Module Level logger



The logging library takes a modular approach and offers several categories of components: loggers, handlers, filters, and formatters.


Loggers expose the interface that application code directly uses.

Handlers send the log records (created by loggers) to the appropriate destination.

Filters provide a finer grained facility for determining which log records to output.

Formatters specify the layout of log records in the final output.



Logging is performed by calling methods on instances of the Logger class (hereafter called loggers). Each instance has a name, and they are conceptually arranged in a namespace hierarchy using dots (periods) as separators. For example, a logger named ‘scan’ is the parent of loggers ‘scan.text’, ‘scan.html’ and ‘scan.pdf’. Logger names can be anything you want, and indicate the area of an application in which a logged message originates.


A good convention to use when naming loggers is to use a module-level logger, in each module which uses logging, named as follows:


logger = logging.getLogger(__name__)




References:

https://docs.python.org/3/howto/logging.html#logging-basic-tutorial


No comments:

Post a Comment