Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

customize appenders within rootCategory

 
Mike Corriston
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to figure out a way to customize an appender without having to create a new Category for it. I have a console appender created off the rootCategory that logs all levels debug and up. I want to have another appender, a fileAppender, created off the rootCategory as well that is assigned the error priority. The formatting of this will use file name and line numbers. I only want line number formatting for errors since its a cpu instensive option. The way I have it now is presented in the config file below:
log4j.rootCategory=DEBUG, A1
# A1 is a ConsoleAppender
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p [%t] - %m%n
#########################################################
log4j.category.com.pge.fileLog=ERROR, A2
log4j.additivity.com.pge.fileLog=false
# A2 is a DailyRollingFileAppender
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.file=logfile.log
log4j.appender.A2.datePattern='.'yyyy-MM-dd
log4j.appender.A2.append=true
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5p %F:%L %d{MMM dd yyyy HH:mm:ss} - %m%n
So the only way I know to have the two appenders work independant of each other is to place them under separate categories. So if I can get one logging object that writes info messages to the console and error messages to the file, that would be ideal. I don't want one appender logging console when I'm wanting to log to file and vice versa. But what this means is in my code I have to load two different loggers:
Logger conLog = SMIPLogger.getStandardLogger();
Logger fileLog = SMIPLogger.getErrorLogger();
Anybody have any ideas/suggestions on this? Thanks.
- MIke
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic