问题描述
1.希望log4j.rootLogger 所有的错误输出到 logs/error.log2.希望log4j.logger.com.fly_hyp 所有的info级别输出到logs/info.log一般我使用 DailyRollingFileAppender我做了很多尝试一直不能完美解决。
解决方案
<appender name="info" class="org.apache.log4j.DailyRollingFileAppender"> <param name="DatePattern" value="'.'yyyy_MM'.txt'" /> <param name="Threshold" value="INFO" /> <param name="Encoding" value="UTF-8"/> <param name="File" value="${xbase.webapp.root}/WEB-INF/logs/info.log" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%5p %d{yyyy/MM/dd HH:mm:ss} %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="WARN" /> </filter> </appender> <appender name="error" class="org.apache.log4j.DailyRollingFileAppender"> <param name="DatePattern" value="'.'yyyy_MM'.txt'" /> <param name="Threshold" value="ERROR" /> <param name="Encoding" value="UTF-8"/> <param name="File" value="${xbase.webapp.root}/WEB-INF/logs/error.log" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%5p %d{yyyy/MM/dd HH:mm:ss} %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="FATAL" /> </filter> </appender>
解决方案二:
<root> <appender-ref ref="info" /> <appender-ref ref="error" /> </root>