Log4j - logger inheritance

R

Roger

I've deployed log4j in my web-app. I've configured the root logger as
log4j.rootlogger=FATAL with a console appender and my application
specific logger as log4j.logger.uk.co.brakes=DEBUG with a RollingFile
appender. However, I'm still seeing log.debug() messages being
displayed on the Tomcat console. I'm obviously missing something here,
but how do I restrict the console appender to display FATAL level
messages only while still being able to log DEBUG level messages to
file.

Regards
Roger
 
G

GaryM

(e-mail address removed) (Roger) wrote in
I've deployed log4j in my web-app. I've configured the root logger
as log4j.rootlogger=FATAL with a console appender and my
application specific logger as log4j.logger.uk.co.brakes=DEBUG
with a RollingFile appender. However, I'm still seeing log.debug()
messages being displayed on the Tomcat console. I'm obviously
missing something here, but how do I restrict the console appender
to display FATAL level messages only while still being able to log
DEBUG level messages to file.

I don't think you can. All *enabled* logging requests will go to all
appenders in the hierarchy. So if you have your package *.brakes set
to debug, then debug messages would go to the appender for that level
AND the root appender. setAddivity(false) disables this behavior,
however it takes rootLogger out of the equation, altogether, which
is, of course, undesirable.

Gary
 
G

GaryM

I don't think you can. All *enabled* logging requests will go to
all appenders in the hierarchy. So if you have your package
*.brakes set to debug, then debug messages would go to the
appender for that level AND the root appender. setAddivity(false)
disables this behavior, however it takes rootLogger out of the
equation, altogether, which is, of course, undesirable.

One further thought. You can specify the Threshold for the appender:

log4j.appender.A1.Threshold=FATAL

The Log request is still propagated to the console logger A1, but
unless is it >= threshold, it won't be accepted.

Hope that helps.

Gary
 
R

Roger

GaryM said:
One further thought. You can specify the Threshold for the appender:

log4j.appender.A1.Threshold=FATAL

The Log request is still propagated to the console logger A1, but
unless is it >= threshold, it won't be accepted.

But surely that's what I'm doing with log4j.rootlogger=FATAL, A1?
According to the guide that comes with the download, if I set the
rootlogger to FATAL then I shouldn't see the DEBUG messages on the
console.
However, specifying the threshold for the appender instead of the
logger appears to do what I wanted. Do you happen to know of any good
documentation for log4j as the basic guide provided makes no mention
of being able to set the threshold for the appender.

Regards and thanks for your assistance
Roger
 
G

GaryM

(e-mail address removed) (Roger) wrote in
But surely that's what I'm doing with log4j.rootlogger=FATAL, A1?
According to the guide that comes with the download, if I set the
rootlogger to FATAL then I shouldn't see the DEBUG messages on the
console.

I agree. It is confusing and I can't rationalize it. If I say that
the Level is a default only to the Logger then you would rightly
say, then why does it act as a threshold *sometimes*. However that
basic manual is clear about it: once a log request is valid it goes
to all loggers in the hierarchy.

Did you happen to notice LevelMatchFilter classes and the Filter
interface? These all go on the Appender using addFilter(Filter). It
seems that from a design perspective filtering and thresholds are
dealt with in the Appender.
However, specifying the threshold for the appender instead of the
logger appears to do what I wanted. Do you happen to know of any
good documentation for log4j as the basic guide provided makes no
mention of being able to set the threshold for the appender.

Not online. The online manual is basic at best. I poked around
and found the mailing list.

Index:

http://nagoya.apache.org/eyebrowse/SummarizeList?listId=201

On Thresholds:

http://nagoya.apache.org/eyebrowse/...=threshold&defaultField=subject&Search=Search
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top