标签:
1、在项目中加入log4php包
2、配置
<configuration xmlns="http://logging.apache.org/log4php/"> <appender name="default" class="LoggerAppenderConsole" /> <appender name="basic_file_appender" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutPattern"> <param name="conversionPattern" value="%date [%logger] %message%newline" /> </layout> <param name="file" value="logs/basic.%s.log" /> <param name="datePattern" value="Y-m-d" /> </appender> <root> <level value="debug" /> <appender_ref ref="basic_file_appender" /> </root> <appender name="route_file_appender" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutPattern"> <param name="conversionPattern" value="%date %p [%logger] %message%newline" /> </layout> <param name="file" value="logs/route.%s.log" /> <param name="threshold" value="error"/> <param name="append" value="true" /> <param name="datePattern" value="Y-m-d" /> </appender> <logger name="Route"> <level value="debug" /> <appender_ref ref="route_file_appender" /> </logger> <appender name="session_file_appender" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutPattern"> <param name="conversionPattern" value="%date [%logger] %message%newline" /> </layout> <param name="file" value="logs/session.%s.log" /> <param name="datePattern" value="Y-m-d" /> </appender> <logger name="Session"> <level value="debug" /> <appender_ref ref="session_file_appender" /> </logger> <appender name="InventoryTransaction_file_appender" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutPattern"> <param name="conversionPattern" value="%date [%logger] %message%newline" /> </layout> <param name="file" value="logs/InventoryTransaction.%s.log" /> <param name="datePattern" value="Y-m-d" /> </appender> <logger name="InventoryTransaction"> <level value="debug"/> <appender_ref ref="InventoryTransaction_file_appender" /> </logger> <appender name="Reserve_file_appender" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutPattern"> <param name="conversionPattern" value="%date [%logger] %message%newline" /> </layout> <param name="file" value="/data0/wmsinventoryapi/Reserve.%s.log" /> <param name="datePattern" value="Y-m-d.H" /> </appender> <logger name="Reserve"> <level value="debug"/> <appender_ref ref="Reserve_file_appender" /> </logger> <appender name="Exception_file_appender" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutPattern"> <param name="conversionPattern" value="%date [%logger] %message%newline" /> </layout> <param name="file" value="logs/exception.%s.log" /> <param name="datePattern" value="Y-m-d" /> </appender> <logger name="Exception"> <level value="error"/> <appender_ref ref="Exception_file_appender" /> </logger> </configuration>
ConversionPattern参数的格式含义
格式名 含义
%c 输出日志信息所属的类的全名
%d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy-MM-dd HH:mm:ss },输出类似:2002-10-18- 22:10:28
%f 输出日志信息所属的类的类名
%l 输出日志事件的发生位置,即输出日志信息的语句处于它所在的类的第几行
%m 输出代码中指定的信息,如log(message)中的message
%n 输出一个回车换行符,Windows平台为“rn”,Unix平台为“n”
%p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL。如果是调用debug()输出的,则为DEBUG,依此类推
%r 输出自应用启动到输出该日志信息所耗费的毫秒数
%t 输出产生该日志事件的线程名
3、使用log4php打印日志
Logger::getLogger("Route")->error(Flight::request());
4、输出结果
标签:
原文地址:http://www.cnblogs.com/sdgf/p/5748716.html