Home>Article>PHP Framework> thinkphp logging configuration tutorial

thinkphp logging configuration tutorial

L
L forward
2020-06-01 17:15:27 7383browse

thinkphp logging configuration tutorial

thinkphp logging

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_RECORDparameter 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:

  1. 'LOG_RECORD' => true, // Turn on logging
  2. #'LOG_LEVEL' =>'EMERG,ALERT,CRIT,ERR', //Only record EMERG ALERT CRIT ERR errors
Log level

ThinkPHP classifies system logs according to levels, including:

  • 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
Recording method

Log The default recording mode is file mode, which can be expanded to support more recording modes through the driver.

The recording method is configured by the LOG_TYPE parameter, for example:

  1. 'LOG_TYPE' => 'File ', //The default logging type is file mode
##File mode record, the corresponding driver file is located in the system's
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:

  1. ##\Think\Log::record('Test log information ');

  1. \Think\Log::record('Test log information, this is the warning level', 'WARN');
  2. ##record method only Information about the log level allowed by the current configuration will be recorded. If the application configuration is:

  1. '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
  1. ::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
  1. ('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: "
  2. TP5

Method ##Log::record() Record log information to memory Log::save() Write the log information saved in memory (using the specified recording method) Log::write() Write a log message in real time The default log level is ERR, you can also specify the log level :::"
Description

The above is the detailed content of thinkphp logging configuration tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete