Go log4php Usage and Configuration Guide
http://www.qinbin.me/log4php-use-and-configuration-guide/
has been a temporary write log component, but now with the continuous improvement of the function, the program's log has also been standardized, but feel that now the log function can not meet the current needs, so consider introducing a perfect log component, look at the log4php feel very good.
Log4php is one of the LOG4XX series of log components, is log4j migrated to PHP version, mainly used to log information, support a variety of input destinations, including: Log files, log rollback files, databases, log servers, etc., but also support a variety of input formats.
Usage examples:
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 = 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 comprised of three important components:
Priority of the log information;
The output destination of the log information;
The output format of the log information.
The priority of log information is from high to low with 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 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), you can set the priority in the configuration file to show or hide debugging information in the code, for example, when I adjust the log level to the Warn level, then the error message in the program (via $log->error ("error Message here! ") ) and warn level information can be recorded, and all information in the program using info and debug level will not be displayed, it is
"Log4php.rootlogger=debug, the first parameter of the A1″ in Rootlogger, which means to define the debug level as the debug level, which means all the error in the program, Warn,info, Debug information can be displayed, if the level is set to info, then there can be only error, WARN, info Three kinds of information can be displayed.
Here are the usage of four different levels:
The debug level indicates that fine-grained information events are very helpful for debugging applications.
The INFO level indicates that the message highlights the application's running process at a coarse-grained scale.
WARN level indicates a potential error situation.
The error level indicates that the system continues to operate without affecting the failure event.
FATAL level indicates that each serious error event will cause the application to exit.
2. The output destination of the log information. 、
12 types of output destinations are supported in log4php, respectively:
In the configuration file is represented as "log4php.rootlogger=debug, default" alias from the second parameter, 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 actual needs, the output destination can have many, the performance is 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 output modes, respectively:
loggerlayouthtml//output debug information in HTML format
loggerlayoutsimple//simple display in "Level information-Log message" format
loggerlayoutttcc//is displayed in the format "month/day/year time [process] level information Log name-debug Information"
loggerpatternlayout//is displayed as an output format as a pattern expression (this is a very powerful feature, you can set the output format as you wish, and explain it in detail in the Example section)
loggerxmllayout//output in XML mode