Disable log4j console logging and enable file logg

2019-02-13 21:02发布

问题:

My log4j.properties file is:

log4j.rootLogger=WARN, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %p [%c] - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${jboss.server.log.dir}/afrodite.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%t] %p [%c] - %m%n

log4j.logger.info.release.scheduler=INFO, scheduler
log4j.appender.scheduler=org.apache.log4j.RollingFileAppender
log4j.appender.scheduler.File=${jboss.server.log.dir}/afrodite_scheduler.log
log4j.appender.scheduler.MaxFileSize=10MB
log4j.appender.scheduler.MaxBackupIndex=10
log4j.appender.scheduler.Append=true
log4j.appender.scheduler.layout=org.apache.log4j.PatternLayout
log4j.appender.scheduler.layout.ConversionPattern=%d [%t] %p [%c] - %m%n 

If I want to disable console output for scheduler logger what should I do? That means scheduler logger only log into file not in console.

Thanks and Regards.

回答1:

Add this line to your config:

log4j.appender.scheduler.additivity=false

log4j.additivity.info.release.scheduler=false

(sorry, first hint was incorrect.)



回答2:

you can add two lines in your properties file.

log4j.rootLogger=ALL, stdout, file,scheduler   (#here ALL declare for all level of logs)

log4j.logger.info.release.scheduler=INFO, scheduler
log4j.additivity.info.release.scheduler=false