The following snippet serves as a cheat sheet for quickly setting up Python
logging module with more detailed output format.
For complete setup instruction, please see the
documentation for Python
Update on 2018-10-10
Quick setup for logging to both a file and the console
Update on 2017-06-07:
Relationships among logger, handler, and formatter:
different loggers are responsible of logging status of different parts of the
code (e.g. a library, module)
logger uses handler to writing logging message to a output media (e.g screen,
handler uses formatter to format the logging message
handler’s logging level overwrites a logger’s level.
Logger logging level as a global restriction on which messages are
“interesting” for a given logger and its handlers. The messages that are
considered by the logger afterwards get sent to the handlers, which perform
their own filtering and logging process.