上QQ阅读APP看书,第一时间看更新
There's more...
The Python logging module has a lot of capabilities, such as the following:
- Further tweaks the format of the log, for example, including the file and line number of the log that was produced.
- Defines different logger objects, each one with its own configuration, like logging level and format. This allows to produce logs to different systems in different ways, though is normally not used for simplicity.
- Sends logs to multiple places, such as that standard output and file, or even a remote logger.
- Automatically rotates logs, creating new log files after a certain time or size. This is handy in keeping logs organized by day, and allowing for the compression or removal of old logs.
- Reads standard logging configurations from files.
Instead of creating complex rules, try to log extensively, but with the proper level, and then filter.
For comprehensive detail, check the Python docs of the module at https://docs.python.org/3.7/library/logging.html, or the tutorial at https://docs.python.org/3.7/howto/logging.html.