Tuesday, June 12, 2007

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

7 comments:

Chip said...

Very helpful. Thanks.

RobertMarkBram said...

Hey Chip - glad it helped you! :)

Anonymous said...

Thank you Rob, I was also suffering the same issue.

Alexx said...

The solution is sooo simple, thanx a lot! I was googling and reading specs since yesterday, to solve the same issue.

RobertMarkBram said...

You're very welcome Alexx and Anon - it makes me happy to hear more people found it useful!

Anonymous said...

Very helpful. Thank you

RobertMarkBram said...

Glad to have helped someone new, Anon. :)