xml配置,输出指定日记级别
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender"> <param name="threshold" value="error"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{(yyyy年MM月dd日-HH時mm分ss秒)} %p [%c] - %m%n " /> </layout> </appender> <appender name="rollingFile.log" class="org.apache.log4j.RollingFileAppender"> <param name="File" value=" D:/temp/SpringMVC.log " /> <param name="threshold" value="info"/> <param name="Append" value="true" /> <param name="MaxBackupIndex" value="2" /> <param name="MaxFileSize" value="1024" /> <layout class="org.apache.log4j.PatternLayout" > <param name="ConversionPattern" value="%d [%t] %p - %m%n" /> </layout> <!-- 实现过滤功能,用这个标签,当往这个指定文件记录日志时只记录指定级别的日志,别的不记录.Filter标签只能在xml配置文件好用,在.properties属性文件中不好用--> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="ERROR"/> <param name="LevelMax" value="ERROR"/> <param name="acceptOnMatch" value="TRUE"/> </filter> </appender> <!-- 封装apache ,这样,可以在java程序中的Category cat2 = Category.getInstance("your.category.name"); 来进行输出日志 --> <category name="org.apache"> <!--设置封装的名称--> <priority value="info" /> <!--输出指定级别的日志--> <appender-ref ref="ConsoleAppender"/> <!--设置输出的目的地--> </category> <root> <level value ="debug" /> <appender-ref ref="ConsoleAppender"/> <appender-ref ref="rollingFile.log"/> <!-- 经过过滤只记录error级别的日志 --> </root> </log4j:configuration> properties配置 log4j.rootLogger=debug, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log log4j.appender.R.MaxFileSize=100KB # Keep one backup file log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d - %p %t %c - %m%n #will extends the rootLogger,配置特定的logger log4j.logger.fundmanage.trade=WARN,trade log4j.appender.trade=org.apache.log4j.DailyRollingFileAppender log4j.appender.trade.File=fundmanage_trade.log log4j.appender.trade.DatePattern='.'yyyy-MM-dd log4j.appender.trade.layout=org.apache.log4j.PatternLayout log4j.appender.trade.layout.ConversionPattern=%d - %p %t %c - %m%n |
http://hi.baidu.com/69hwj/blog/item/eae15ace90a29e3cb600c8e6.html