H T
H T

Reputation: 23

java log4j - log to both category and root logger

I've got the following problem - This is my log4j config file:

log4j.rootLogger=info, stdout, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logs/example.log

log4j.category.A3=, A3
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.File=logs/A3.log

And this is my java code:

final static private Logger loggerA3 = Logger.getLogger("A3");
loggerA3.info("abcd");

Now, the abcd string appears in both example.log and A3.log, but I only want it to appear in A3.log, what should I do?

Upvotes: 2

Views: 4596

Answers (1)

Sandeep Nair
Sandeep Nair

Reputation: 3650

Please add the following line in log4j config file

log4j.additivity.A3=false

This will ensure that log is not appended to root logger

Upvotes: 5

Related Questions