Log4J: duplicate Lines in output?

Ever see duplicate lines in your log4j output? Something like this perhaps:

2006-08-12 18:30:00,783 DEBUG  com.cml.etech.eForms.sys.AbstractQuartzJobRouter - Start of execute
2006-08-12 18:30:00,783 DEBUG  com.cml.etech.eForms.sys.AbstractQuartzJobRouter - Start of execute
2006-08-12 18:30:00,783 DEBUG  com.cml.etech.eForms.sys.QuartzJobServletRouter - About to issue getContent() request
2006-08-12 18:30:00,783 DEBUG  com.cml.etech.eForms.sys.QuartzJobServletRouter - About to issue getContent() request

The reason could be duplicate loggers specified in your log4j configuration. For example:

log4j.rootLogger=INFO, file
log4j.logger.com.cml.etech=debug, file

This is telling log4j that the root logger should output to a file appender called "file" and that all classes in com.cml.etech should also log to a file appender called "file". The fix is easy: just remove "file" from the second logger definition, as per below.

log4j.rootLogger=INFO, file
log4j.logger.com.cml.etech=debug

Comments

Hey Chip - glad it helped you! :)
Anonymous said…
Thank you Rob, I was also suffering the same issue.
Anonymous said…
The solution is sooo simple, thanx a lot! I was googling and reading specs since yesterday, to solve the same issue.
You're very welcome Alexx and Anon - it makes me happy to hear more people found it useful!
Anonymous said…
Very helpful. Thank you
Glad to have helped someone new, Anon. :)

Popular Posts