1, add log4php package in the project
2. Configuration
<Configurationxmlns= "http://logging.apache.org/log4php/"> <Appendername= "Default"class= "Loggerappenderconsole" /> <Appendername= "Basic_file_appender"class= "Loggerappenderdailyfile"> <Layoutclass= "Loggerlayoutpattern"> <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" /> </Layout> <paramname= "File"value= "Logs/basic.%s.log" /> <paramname= "Datepattern"value= "y-m-d" /> </Appender> <Root> < Levelvalue= "Debug" /> <Appender_refref= "Basic_file_appender" /> </Root> <Appendername= "Route_file_appender"class= "Loggerappenderdailyfile"> <Layoutclass= "Loggerlayoutpattern"> <paramname= "Conversionpattern"value= "%date%p [%logger]%message%newline" /> </Layout> <paramname= "File"value= "Logs/route.%s.log" /> <paramname= "threshold"value= "Error"/> <paramname= "Append"value= "true" /> <paramname= "Datepattern"value= "y-m-d" /> </Appender> <Loggername= "Route"> < Levelvalue= "Debug" /> <Appender_refref= "Route_file_appender" /> </Logger> <Appendername= "Session_file_appender"class= "Loggerappenderdailyfile"> <Layoutclass= "Loggerlayoutpattern"> <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" /> </Layout> <paramname= "File"value= "Logs/session.%s.log" /> <paramname= "Datepattern"value= "y-m-d" /> </Appender> <Loggername= "Session"> < Levelvalue= "Debug" /> <Appender_refref= "Session_file_appender" /> </Logger> <Appendername= "Inventorytransaction_file_appender"class= "Loggerappenderdailyfile"> <Layoutclass= "Loggerlayoutpattern"> <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" /> </Layout> <paramname= "File"value= "Logs/inventorytransaction.%s.log" /> <paramname= "Datepattern"value= "y-m-d" /> </Appender> <Loggername= "Inventorytransaction"> < Levelvalue= "Debug"/> <Appender_refref= "Inventorytransaction_file_appender" /> </Logger> <Appendername= "Reserve_file_appender"class= "Loggerappenderdailyfile"> <Layoutclass= "Loggerlayoutpattern"> <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" /> </Layout> <paramname= "File"value= "/data0/wmsinventoryapi/reserve.%s.log" /> <paramname= "Datepattern"value= "Y-m-d.h" /> </Appender> <Loggername= "Reserve"> < Levelvalue= "Debug"/> <Appender_refref= "Reserve_file_appender" /> </Logger> <Appendername= "Exception_file_appender"class= "Loggerappenderdailyfile"> <Layoutclass= "Loggerlayoutpattern"> <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" /> </Layout> <paramname= "File"value= "Logs/exception.%s.log" /> <paramname= "Datepattern"value= "y-m-d" /> </Appender> <Loggername= "Exception"> < Levelvalue= "Error"/> <Appender_refref= "Exception_file_appender" /> </Logger> </Configuration>
The format meaning of the Conversionpattern parameter
Format name meaning
The full name of the class to which the%c output log information belongs
%d the date or time of the output log time, the default format is ISO8601, or the format can be specified later, for example:%d{yyy-mm-dd HH:mm:ss}, output similar to: 2002-10-18-22:10:28
%f the class name of the class to which the output log information belongs
%l the occurrence of the output log event where the statement that outputs the log information is in the first line of the class it is in
%m the information specified in the output code, such as a message in log (message)
%n output a carriage return newline character, Windows platform is "RN", UNIX platform is "n"
%p output priority, or debug,info,warn,error,fatal. Debug if the debug () output is called, and so on
%r the number of milliseconds that the output from the application starts to output this log information
%t output The name of the thread that generated the log event
3. Print logs using log4php
Logger::getlogger ("Route")->error (Flight::request ());
4. Output results
log4php Use and Configuration