// shall I write some keywords here to boost search engine ranking?

Thursday, March 05, 2009

Duplicate log in log4j

If you have log4j configured as below, you will notice that log entry from "yourLogger" will duplicate in appender


log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info, stdout


To solve this, just change your configuration to:


log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info, stdout
log4j.additivity.yourLogger=false

9 comments:

Anonymous said...

Thank you m8 - it helped.
cheers!

Anonymous said...

Thanks, it resolved my issue.

Anonymous said...

thanks!

Anonymous said...

works for those using XML

Anonymous said...

what does yourLogger stands for? is it an actual configuration? I don't get it as most of blogs on log4j do.

Anonymous said...

What does yourLogger stands for? Is it really an actual code for log4j configuration? I don't get it as most of other blogs on log4j do. Still very ambigous, sorry.

Anonymous said...

Thanks, very small, concise article, It solved my probem :)

Thiam Teck (1983 - ?) said...

"yourLogger" refer to logger name.

In java code, we usually do this :
Logger logger = Logger.getLogger(this.getClass());

So let say your class name is "com.abc.HelloWorld", logger name is "com.abc.HelloWorld". (in log4j properties file, it will be "log4j.logger.com.abc.HelloWorld")

However, log4j logger also work by prefix, so "log4j.logger.com.abc" will work too.

René said...

another solution would have been to remove the appender definition from

log4j.logger.yourLogger=info, stdout

Like this:

log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info

I found this here: http://robertmarkbramprogrammer.blogspot.de/2007/06/log4j-duplicate-lines-in-output.html