This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Is there any way to change root logger for different appenders in the same log4.properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Is there any way to change root logger for different appenders in the same log4.properties file" Watch "Is there any way to change root logger for different appenders in the same log4.properties file" New topic
Author

Is there any way to change root logger for different appenders in the same log4.properties file

Abhijit Kangale
Ranch Hand

Joined: Sep 17, 2009
Posts: 39
Hi,

I have used log4j framework in my application with below log4j.properties file configuration.

#Console appender
log4j.rootLogger=DEBUG, stdout, rollFile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= [%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n


#Rolling file appender
log4j.appender.rollFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollFile.File=Out.txt
log4j.appender.rollFile.MaxFileSize=10MB
log4j.appender.rollFile.MaxBackupIndex=1
log4j.appender.rollFile.Append=true
log4j.appender.rollFile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollFile.layout.ConversionPattern= %d [ %-5p ] %c | %m | %t | %x %n

Here I can use only single root logger. But if I want to use different root logger for different appenders (like for ConsoleAppender -DEBUG and for RollingFileAppender - ERROR), is there any way to implement such approach?

Thanks in advance,
Abhijit
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18714
    
    8

I can understand why you want to use different loggers, but why different root loggers? You're just making things hard for yourself if you try to do things which can't be done. Just use different loggers and skip the root logger entirely if you don't need it.
 
jQuery in Action, 2nd edition
 
subject: Is there any way to change root logger for different appenders in the same log4.properties file