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:
Thank you m8 - it helped.
cheers!
Thanks, it resolved my issue.
thanks!
works for those using XML
what does yourLogger stands for? is it an actual configuration? I don't get it as most of blogs on log4j do.
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.
Thanks, very small, concise article, It solved my probem :)
"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.
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
Post a Comment