Here's what I'm trying to do: I want 2 log files: The first logs INFO level and up for all parts of the applications but also logs DEBUG and up for some packages. The second only logs ERROR and up across all packages. I'm sure this is probably trivial but I can't quite figure it out. Here is the configuration file I am currently using:
log4j.rootLogger=INFO,console,R
#console appender
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %t %-5p %c{2} - %m%n
#file appender
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern = '.'yyyy-MM-dd
log4j.appender.R.File = log/log.txt
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = [%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n
#Specific log levels
log4j.category.com.mypackage1=DEBUG
log4j.category.com.mypackage2=DEBUG
This doesn't have the error log part, obviously. My basic idea was to add another appender and set its log level to ERROR but the categories seem to override it and and their info in as well, which is not what I want. The reason they are there is because the other packages dump alot of information that we don't need when set to debug and this is how we are getting around it. I'm thinking there may be a better overall approach to this but this is my first log4j config file ever.
UPDATE: A co-worker suggested using 2 loggers as is mentioned in the post that kdgregory linked to in his comment (http://stackoverflow.com/questions/1008122/different-log4j-layout-for-debug-and-error/1008176#1008176). People there seemed to think it was a bad idea but no one ever explained why. It does seem a bit hacky but it does what we need. What are the main reasons to not use that method (other than having to maintain 2 different loggers)?