In log4j, is there a way to have logger.error("") and logger.debug("") include different output layouts?
I'd like errors to include method names and line numbers, both of which slow down application performance.
EDIT:
After adding apache-log4j-extras, the following config file works.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="WARNINGS" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="warnings.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss} %-5p %c - %m%n%n"/>
</layout>
<filter class="org.apache.log4j.filter.LevelRangeFilter">
<param name="LevelMin" value="DEBUG"/>
<param name="LevelMax" value="WARN"/>
</filter>
</appender>
<appender name="ERRORS" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="errors.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- %M for method name , %L for line number -->
<param name="ConversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss} %-5p %c %M %L - %m%n%n"/>
</layout>
<filter class="org.apache.log4j.filter.LevelRangeFilter">
<param name="LevelMin" value="ERROR"/>
<param name="LevelMax" value="FATAL"/>
</filter>
</appender>
<logger name="com.foo.bar">
<appender-ref ref="WARNINGS"/>
<appender-ref ref="ERRORS"/>
</logger>
</log4j:configuration>
This code was used to test
// goes to errors.txt
log.error("error");
//goes to warnings.txt
log.warn("warn");