Using the Python logging module
Logging is a fundamental requirement for any reasonably sized application. Logging not only helps in debugging and troubleshooting but also provides insight into details of an application's internal issues. A few advantages of logging are as follows:
- Debugging code, especially to diagnose why and when an application failed or crashed
- Diagnosing unusual application behavior
- Providing auditing data for regulatory or legal compliance matters
- Identifying users' behaviors and malicious attempts to access unauthorized resources
Before discussing any practical examples of logging, we will first discuss the key components of the logging system in Python.
Introducing core logging components
The following components are fundamental to set up logging for an application in Python:
- Logger
- Logging levels
- Logging formatter
- Logging handler
A high-level architecture of the Python logging system can...