The processing of logs is automatically performed by the system. When logging is turned on, Record all log information for the allowed log levels.
For performance reasons, the SQL log level must be valid when debugging mode is turned on, otherwise it will not be recorded. System logging is completed by the core Think\Log class and its driver, which provides multiple ways to record different levels of log information.
By default, logging is only recorded in debug mode. To enable logging in deployment mode, theLOG_RECORD
parameter must be enabled in the configuration, and the logs that need to be recorded can be configured in the application configuration file. Level, for example:
'LOG_RECORD' => true, // Turn on logging
#'LOG_LEVEL' =>'EMERG,ALERT,CRIT,ERR', //Only record EMERG ALERT CRIT ERR errors
- EMERGSerious error, causing system crash and unavailability
- ALERTAlert error, error that must be corrected immediately
- CRITCritical value Error, error exceeding the critical value
- ERRGeneral error
- WARNWarning error, error requiring warning
- NOTICENotification, the program can run but it is not perfect error
- INFOInformation, the program output information
- DEBUGDebugging, used for debugging information
- SQLSQL statement, this level is only valid when debugging mode is turned on
'LOG_TYPE' => 'File ', //The default logging type is file mode
Library/Think/Log/Driver/File.class.php.
Manual recording
Generally, the system's logging is automatic and manual recording is not required. However, sometimes it is also necessary to manually record log information. The Log class provides 3 Method for logging.
Since the system will automatically call the Log::save method after the request is completed, usually, you only need to call Log::record to record the log information.
The usage of record method is as follows:
##\Think\Log::record('Test log information ');
\Think\Log::record('Test log information, this is the warning level', 'WARN');
##record method only Information about the log level allowed by the current configuration will be recorded. If the application configuration is:
- 'LOG_LEVEL'
=>'EMERG, ALERT,CRIT,ERR', //Only record EMERG ALERT CRIT ERR errors
## Then the log information recorded by the above record method will be filtered directly, or you can force recording:
-
\Think\Log
- ::
record('Test log information, this is the warning level','WARN',true);##The log information recorded using the record method is not saved in real time. If you need to record in real time, you can use the write method, for example:
##\Think\Log
-
write
- (
'Test Log information, this is the warning level, and is written in real time ','WARN'); The write method is not affected by the configured allowed log level when writing logs, and can write any level of log information in real time.
Recommended tutorial: " TP5
Description | |
---|---|
Log::save() | |
Log::write() | |
The default log level is ERR, you can also specify the log level :::" |