search
HomePHP FrameworkThinkPHPthinkphp logging configuration tutorial

thinkphp logging configuration tutorial

Jun 01, 2020 pm 05:15 PM
thinkphp

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, the LOG_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:

  1. <span class="str">'LOG_RECORD'<span class="pln"> <span class="pun">=><span class="pln"> <span class="kwd">true<span class="pun">,<span class="pln"> <span class="com">// Turn on logging</span></span></span></span></span></span></span></span>
  2. #'LOG_LEVEL'<span class="str"> <span class="pln">=><span class="pun">'EMERG,ALERT,CRIT,ERR'<span class="str">,<span class="pun"> <span class="pln">//Only record EMERG ALERT CRIT ERR errors <span class="com"></span></span></span></span> </span></span></span>
Log level

ThinkPHP classifies system logs according to levels, including:

  • EMERG Serious error, causing system crash and unavailability
  • ALERT Alert error, error that must be corrected immediately
  • CRIT Critical value Error, error exceeding the critical value
  • ERR General error
  • WARN Warning error, error requiring warning
  • NOTICE Notification, the program can run but it is not perfect error
  • INFO Information, the program output information
  • DEBUG Debugging, used for debugging information
  • SQL SQL 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'<span class="str"> <span class="pln">=><span class="pun"> <span class="pln">'File '<span class="str">,<span class="pun"> <span class="pln">//The default logging type is file mode<span class="com"></span></span></span></span></span></span></span></span>
##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.

Method##Log::record()Record log information to memoryLog::save()Write the log information saved in memory (using the specified recording method)Log::write()Write a log message in real time

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<span class="pln">::<span class="pun">record<span class="pln">(<span class="pun">'Test log information '<span class="str">);<span class="pun"></span></span></span></span></span></span>
The default log level is ERR, you can also specify the log level :

  1. \Think\Log<span class="pln">::<span class="pun">record<span class="pln">(<span class="pun">'Test log information, this is the warning level'<span class="str">, <span class="pun">'WARN'<span class="str">);<span class="pun"></span></span></span></span></span></span></span></span>
  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' <span class="str">=><span class="pln">'EMERG, ALERT,CRIT,ERR'<span class="pun">,<span class="str"> <span class="pun">//Only record EMERG ALERT CRIT ERR errors<span class="pln"><span class="com"></span></span></span></span></span></span> </span>## Then the log information recorded by the above record method will be filtered directly, or you can force recording:

    \Think\Log
  1. ::record<span class="pln">(<span class="pun">'Test log information, this is the warning level'<span class="pln">,<span class="pun">'WARN'<span class="str">,<span class="pun">true<span class="str">);<span class="pun"><span class="kwd"><span class="pun"></span></span></span></span></span></span></span></span></span></span>##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 '<span class="pln">,<span class="pun">'WARN'<span class="pln">);<span class="pun"><span class="str"><span class="pun"><span class="str"><span class="pun"></span></span> </span></span></span></span></span>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. </span>Recommended tutorial: "
  2. TP5
"

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. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.