DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Thomas has posted 33 posts at DZone. View Full User Profile

Multiple Log4j Appenders With Different Levels

07.08.2010
| 4435 views |
  • submit to reddit
        
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>

 <appender name="debugDailyRollingFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
  <param name="datePattern" value="'.'yyyy-MM-dd" />
  <param name="file" value="/tmp/log/debug.log" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%t] %c - %m%n" />
  </layout>
 </appender>
 
 <appender name="errorDailyRollingFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
  <param name="datePattern" value="'.'yyyy-MM-dd" />
  <param name="file" value="/tmp/log/error.log" />
  <param name="threshold" value="error" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%t] %c - %m%n" />
  </layout>
 </appender>

 <logger name="my.app.package">
  <level value="debug" />
 </logger>

 <root>
  <priority value="warn" />
  <appender-ref ref="debugDailyRollingFileAppender" />
  <appender-ref ref="errorDailyRollingFileAppender" />
 </root>

</log4j:configuration>