Reputation: 3384
I'm using Log4J for logging in my Java Project with Baic Configurator, which is working in a weird fashion. where it logs statements in console with incrementing number of times.
But If I check my Log File then everything is logged exactly once just like required.
Upvotes: 0
Views: 242
Reputation: 3384
Finally adding following to my log4j.properties solved the problem:
# Root logger option
log4j.rootLogger=DEBUG, stdout
# Redirect log messages to console
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=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Upvotes: 0
Reputation: 11
Duplicate logging can happen if we have same appender in multiple Logger configurations.
Example
log4j.logger.com.demo = WARN, out
log4j.logger.com.demo.moduleone = ERROR, out
To avoid it set logger additivity to false. log4j.additivity.com.demo.moduleone = false
Upvotes: 1