How can I set up log4j to use two separate patterns based on the logging level of the message?
For example, right now I'm using the following which applies to all levels:
log4j.appender.stdout.layout.ConversionPattern=%-5p %d{HH\:mm\:ss} - %m%n
What I'd like to do is use a different pattern for levels of WARN and above. Such as:
%-5p %d{HH\:mm\:ss} - [%L:%C] %m%n
To output the line number and class where the warning or error occurred. The extra cost of pulling the caller information would be worth it in situations where a warning or error occurs.
Is this doable?
Here is my full log4j.properties file:
log4j.rootLogger=WARN, stdout1, stdout2
log4j.category.my.package=DEBUG
log4j.appender.stdout1=org.apache.log4j.ConsoleAppender
log4j.appender.stdout1.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout1.layout.ConversionPattern=%-5p %d{HH\:mm\:ss} - %m%n
log4j.appender.stdout2=org.apache.log4j.ConsoleAppender
log4j.appender.stdout2.threshold=WARN
log4j.appender.stdout2.target=System.err
log4j.appender.stdout2.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout2.layout.ConversionPattern=%-5p %d{HH\:mm\:ss} - [%t] [%L:%C] %m%n
EDIT
threshold
looks to be what I need to log all levels of WARN
and higher. Is there a similar property that will configure the other appender to log all levels of INFO
and lower?