wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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: 18541
    
    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.
 
 
subject: Is there any way to change root logger for different appenders in the same log4.properties file
 
Similar Threads
REG : Struts 2 logging
Log4j not working as expected with ejb module
question on log4j and eclipse
Log4J Configuration Problem
thread safe logging in a servlet