0
votes

I am currently fine-tuning my log4j config of a relatively large project. Currently I have not yet configured the log-levels for all locations that could create log entries.

I would like to have log4j have some sort of fallback appender to log all messages for which no other appender has been configured. So if for example I have a log message to:

log to: a.b.c.d:WARN

and have an appender configured to log packages a.b.c with level INFO, then the output is logged to that appender.

If however I have no appender configured to handle a.b.c.d then the fallback should be used.

If I would have configured my a.b.c Appender to level FATAL, then nothing should be logged at all, as I deliberately configured log4j to leave these messages away.

I hope I was able to explain what I want to do :-)

Any suggestions?

Chris

2
Isn't this the default behaviour? - Keppil
Hmmm ... well in my case I have the rootLogger logging everything the others are logging in one big log-file :-( Perhaps I'm configuring the rootLogger wrong. - Christofer Dutz
If you don't want to get everything in the root logger, you can set the additivity=false flag on the other appenders, then the logs won't propagate. Is that what you meant? - Keppil
Geee ... thanks for that :-) It seems to be as allways ... as long as you don't know the magic word you search without success :-( ... I would have accepted your answer, If I could ;-) ... so If you just suggest your "additivity" solution, I will gladly accept it. - Christofer Dutz

2 Answers

1
votes

If you don't want to get everything in you root logger, you can set the

additivity = "false"

on the other loggers. Then the logs won't propagate.

0
votes

I think @Keppil seems mixing up something.

Additivity is something set on Logger, and it control how the settings of parent loggers (includes appender) propagate to the logger.

So, in OP's case, you may do something like this:

Root Logger -> Appender1
Logger a.b.c -> additivity = false, Appender2

By doing so, a.b.c (and all its children) will send its log to Appender2, while all other loggers will send to Appender1.