Django uses the Python buildin logging module.
The Python logging consists of four parts:
- Loggers-Loggers
- Handles-processor
- Filters-Filter
- Formatters-Format Device
Loggers
Logger, Recorder. A logger is a log system entity, each logger is a well-named information "Bucket", in the process of program execution, you can write information inside.
The log level is set for each logger, which describes the severity of the logger's logging information. There are several types of log level:
1, Debug: Low-level system information, commonly used for debugging
2. Info: General System Information
3, WARNING: Warning message,
4. Error: Wrong message,
5. CRITICAL: Severity Information
Each piece of information that is written to the logger is called a log record. Each log record also has a log level to indicate the severity of the log record. Each log record also contains some useful elements that describe what kind of event this log record describes.
When a log message is sent to the logger, the log level is compared to the logger's log level. This information is sent to the processor if the log level of logging information reaches or exceeds the logger's log levels. Otherwise, this message is ignored.
Once the recorder decides that the information is to be processed further, this message will be passed to handler.
Handlers
Handlers, processor. Like an engine, decide what to do with each piece of information written into the logger. It shows a special recording behavior, such as writing this information on the screen, writing to a file, or writing to a network socket.
Like a logger, handlers also has log level control. If the log level of the information does not reach or exceed the log level of handler, then handler will ignore the message.
A logger can have multiple handlers, and each handler can have a different log level. In this way, different notifications can be provided based on the severity level of the information. For example, you can set another severity level of Erroe and critical for handler, for a paging service. At the same time, set up a handler to record all the severity levels of information to provide for further analysis.
Filters
Filters, filter. Provides some additional filtering functions for information to be transmitted from the logger to the handler.
By default, any log information that reaches the log level will be processed. However, if you configure filter, you can add some additional filtering functionality during the logging process. For example, you only allow error messages from a given source to be sent to handler.
Filters can also modify the level of logging. For example, you can write a filter, set in some special cases, to downgrade the error level logging to the warning level.
Filters can be set in loggers and handlers. Multiple filters can act on one place at a time and act as a multi-filtration function.
Formatters
Formatters, formatter. A log record needs to be presented as text, formatters defines the format of the text. A formatter is typically made up of a python format string. However, you can also customize the format.
Introduction to Django Logging