log4php2.3.0 Use explanation
1. What is log4php
Log4php it for the Apche organization Maintenance project, is one of the LOG4XX series of log components, log4j in Java can be regarded as the famous log development package. Log4php also exists as a separate subproject that can be easily loaded using.
Apache Official website: http://logging.apache.org/log4php/
Another log4php's main station: http://www.vxr.it/log4php/
2.log4php directory Structure
After downloading from Apache official website, the extracted folder directory is as follows:
The main core code for the required log4php is below src/main/php,
Simple use of 3.log4php
1. Creating an XML configuration file for log4php
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Configurationxmlns= "http://logging.apache.org/log4php/">3 <!--appender for standard console output -4 <Appendername= "STDOUT"class= "Loggerappenderconsole">5 <paramname= "threshold"value= "Debug"/>6 <Layoutclass= "Loggerlayoutpattern" >7 <paramname= "Conversionpattern"value= "[%date{y-m-d h:i:s,u}] [%t]%-5p%l-%message%newline%ex"/>8 </Layout>9 </Appender>Ten One <!--Log All error log Appender - A <Appendername= "Error-all"class= "Loggerappenderdailyfile"> - <Layoutclass= "Loggerlayoutpattern" > - <paramname= "Conversionpattern"value= "[%date{y-m-d h:i:s,u}] [%t]%-5p%l-%message%newline%ex"/> the </Layout> - <paramname= "File"value= "log/php-error.log.%s" /> - <paramname= "threshold"value= "Error"/> - <paramname= "Append"value= "true" /> + <paramname= "Datepattern"value= "y-m-d" /> - </Appender> + A <!--Log all debug logs for Appender - at <Appendername= "Debug-all"class= "Loggerappenderdailyfile"> - <Layoutclass= "Loggerlayoutpattern" > - <paramname= "Conversionpattern"value= "[%date{y-m-d h:i:s,u}] [%t]%-5p%l-%message%newline%ex"/> - </Layout> - <paramname= "File"value= "log/php-debug.log.%s" /> - <paramname= "threshold"value= "Debug"/> in <paramname= "Append"value= "true" /> - <paramname= "Datepattern"value= "y-m-d" /> to </Appender> + - <!--Log all info logs for Appender - the <Appendername= "Info-all"class= "Loggerappenderdailyfile"> * <Layoutclass= "Loggerlayoutpattern" > $ <paramname= "Conversionpattern"value= "[%date{y-m-d h:i:s,u}] [%t]%-5p%l-%message%newline%ex"/>Panax Notoginseng </Layout> - <paramname= "File"value= "log/php-info.log.%s" /> the <paramname= "threshold"value= "Info"/> + <paramname= "Append"value= "true" /> A <paramname= "Datepattern"value= "y-m-d" /> the </Appender> + - <Root> $ < Levelvalue= "Warn"/> $ <Appender-refref= "STDOUT"/> - <Appender-refref= "Debug-all"/> - <Appender-refref= "Info-all"/> the <Appender-refref= "Error-all"/> - </Root>Wuyi </Configuration>
2. Simple PHP Test
1<?PHP2 require_once(' log4php/logger.php ');3Logger::configure (' Log4php.xml ');4 $pay= Logger::Getrootlogger ();5 $pay->info (' Test log4php ');6 //$pay->warn ("Test log4php");7 //$pay->debug ("Test log4php");8 //$pay->error ("Test log4php");9 //$pay->fatal ("Test log4php");Ten?>
Run the php file, i.e.:
Info, debug does not produce files
Warn generate two files: php-debug.log*** php-info.log***
Errror fatal will produce three files: php-debug.log*** php-error.log*** php-info.log***
4.log4php configuration file Explanation
1) log4php is composed of three parts:
(1) Priority from low to High: Debug, info, warn, error, fatal, log output and your level settings related, such as the above configuration file, root level = Debug so all levels will appear log, but the number of log files is not equal
(2) The destination of the log output (there are many kinds, databases, files, etc.)
Loggerappenderconsole//take php://stdout as the output groundLoggerappenderdailyfile//inherit from loggerappenderfile, file as output, output a file dailyLoggerappenderdb//take the database as the output groundLoggerappenderecho//in the execution of the end of file outputLoggerappenderfile//file as the output groundLoggerappendermail//e-mail as the output placeLoggerappendermailevent//inherit from Loggerappendermail, with mail as output, trigger for eventLoggerappendernull//do not output any informationloggerappenderphp//Output to PHP error message, convert various log level information to PHP standard InformationLoggerappenderrollingfile//inherit from Loggerappenderfile, output in the form of Xxx.log.1, xxx.log.2 ,Loggerappendersocket//output in socket modeLoggerappendersyslog//output to the system log as the destination, using the syslog () function in PHP to record
(3) Output format: The format of the log output, log4php has 5 kinds of output mode
loggerlayouthtml// output debug information in HTML format loggerlayoutsimple// simple display in "Level information-log information" format LOGGERLAYOUTTTCC/ / in the format of "Month/day/year time [process] level information Log name-debug information" to display loggerpatternlayout// The pattern expression is displayed as the output format (this feature is extremely powerful, you can set the output format as you wish, in detail in the Example section)loggerxmllayout// in XML mode to output
This allows you to configure different configurations for each product module by creating multiple profiles and using a flexible management log directory.
Article Source: http://dreameng.blog.51cto.com/1187899/1410361
log4php Configuration and use