Go Guide for use and configuration of log4php

Source: Internet
Author: User
Tags php error system log
http://www.qinbin.me/log4php-use-and-configuration-guide/


has been a temporary write the log component, but now with the continuous improvement of the function, the program's log also made the specification, but feel that the current log function can not meet the needs of the present, so consider introducing a comprehensive log components, look at the log4php feel very good.
Log4php is one of the LOG4XX series log components, the log4j migration to PHP version, mainly used to record log information, support a variety of input destinations, including: Log files, log rollback files, databases, log servers, etc., also supports a variety of input formats.
Use instance:

1234567 require_once ' log4php/logger.php '; Logger::configure (' logger.properties '); $logger = Logger::getrootlogger (); $logger->debug ("Hello world!"); $logger->info ("Hello world!"); $logger->warn ("Hello world!"); $logger->error ("Hello world!");

Appender.default = Loggerappenderrollingfile Log4php.appender.default.file = logger.log.php Log4php.appender.default.layout = Loggerlayoutpattern Log4php.appender.default.MaxFileSize = 1024 Log4php.appender.default.MaxBackupIndex = Ten Log4php.appender.default.layout.ConversionPattern = "%d{iso8601} [%p]%c :%m (at%F line%l)%n "Log4php.rootlogger = DEBUG, default
Configuration Item Description:
The log4php is composed of three important components:
Priority of log information;
The output destination of the log information;
The output format of the log information.
Log information priority from high to low have error, WARN, INFO, DEBUG, respectively, to specify the importance of this log information; the output destination of the log information specifies whether the log will be appended to the end of the execution file or the file, and the output format controls the display of the log information.
1. Priority of the log.
There are four categories of log information (commonly used) that can be displayed or hidden by setting precedence in the configuration file, for example, when I adjust the log level to the Warn level, the error information that appears in the program (via $log->error ("error Message here! ") And warn level information can be recorded, and all information used in the program using the info and debug level will not be displayed, it is
"Log4php.rootlogger=debug, the first parameter definition of Rootlogger in A1″, which means that the debug level is defined as the debug level, which means that all the error in the program, Warn,info, Debug information can be displayed, if the level set to info, then only have the error, WARN, info These three kinds of information can be displayed.
The following are common four levels of usage:
The debug level indicates that fine-grained informational events are useful for debugging applications.
The INFO level indicates that the message highlights the application's running process at the coarse-grained levels.
The WARN level indicates a scenario where a potential error occurs.
The error level indicates that, while an incorrect event occurs, it does not affect the continued operation of the system.
FATAL level indicates that each serious error event will cause the application to exit.
2. The output destination of the log information. 、
The output destinations in log4php support 12 kinds, respectively:
<?php loggerappenderconsole///   php://stdout for Output loggerappenderdailyfile//inheritance from Loggerappenderfile, to file as output, Output a file Loggerappenderdb///per day   with the database as output Loggerappenderecho////At the end of the execution file Loggerappenderfile//file as output Loggerappendermail///loggerappendermailevent//Inherit from Loggerappendermail, mail as output, triggering loggerappendernull for event// Do not output any information loggerappenderphp//output to PHP error messages, all kinds of log level information into PHP standard information loggerappenderrollingfile//inherit from Loggerappenderfile, In the form of xxx.log.1, xxx.log.2 output, loggerappendersocket//Socket output Loggerappendersyslog//to the system log as the destination output, using the syslog in PHP () function to record   ?>



In the configuration file, "Log4php.rootlogger=debug, default" is an alias from the second argument, and the specific destination is set by:
Log4php.appender.default=loggerappenderecho log4php.appender.default.layout=loggerlayouthtml

To achieve, each output destination has a different set of parameters, according to the actual needs, the output destination can have a number of items, performance as follows:
Log4php.rootlogger=debug, default, Qinbin1, Qinbin2, ....
Where default, Qinbin1, qinbin2 represent different output destinations.
3. log file output format. It exists as an attribute of the output destination, and the log4php contains 5 different modes of output, respectively:
loggerlayouthtml//output debug information in HTML format
loggerlayoutsimple//simple to display in the format of "level information-log information"
loggerlayoutttcc//is displayed in the format of "Month/day/year [process] level information Log name-debug Information"
The loggerpatternlayout//is displayed as a pattern expression in the output format (this is extremely powerful, you can set the output format as you wish, in detail in the instance section)
loggerxmllayout//is exported in XML mode


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.