简体   繁体   中英

Log4J is creating incrementing no of logs in console

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.

在此处输入图片说明

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM