Search code examples
propertieslog4jappender

Log4j properties for separate appender


I have the log4j logger and need to send the logger named "ThermoCommandLogger" to separate file and nothing anywhere more (not write it to output or standard file). I tried the following configuration, but the logger debug messages keep on writing to root logger (although it has the INFO level):

# Root logger
log4j.rootLogger=INFO, out, osgi:VmLogAppender

# File appender
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-        32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.out.file=${karaf.data}/log/servicemix.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=10MB
log4j.appender.out.maxBackupIndex=10


#DRF appender
log4j.appender.drf=org.apache.log4j.RollingFileAppender
log4j.appender.drf.layout=org.apache.log4j.PatternLayout
log4j.appender.drf.layout.ConversionPattern=%d{ABSOLUTE} | %m%n
log4j.appender.drf.file=${karaf.data}/log/drfx.log
log4j.appender.drf.append=true   


#Log thermo commands to separate file
log4j.logger.ThermoCommandLogger=DEBUG, drf

Thanks


Solution

  • You need to set "ThermoCommandLogger" logger's additivity to "false", this way you'll stop the flow of log message down the logger chain. You could switch to xml configuration file, see, for example, here: log4j and weblogic: duplicate log messages, or you could try:

    log4j.additivity.ThermoCommandLogger=false