logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: parent logger to filter child logger by level
Date Mon, 17 Dec 2007 19:39:54 GMT

On Dec 17, 2007, at 1:05 PM, Mak, Howard wrote:

> I'm trying to duplicate WARN logs to a separate file by using the  
> below log4j.properties.
>        log4j.rootLogger       = WARN, <appender_1>
>        log4j.logger.MYLOG     = ALL, <appender_2>
>        log4j.additivity.MYLOG = true
> However, appender_1 contains more stuff than I want.
> Am I wrong to expect that rootlogger will filter out all logs other  
> thatn MYLOG @ <WARN> or <ERROR>?

Yes.  appender_1 will should receive all logging requests with a level  
of WARN or higher and any logging requests sent to the "MYLOG"  
appender regardless of level.

There are two independent concepts, one is the effective level  
threshold of a logger and the other is the destination of any logging  
events that satisfy the effective level threshold.

The effective level of a logger is the level of its nearest ancestor  
with an explicitly set level and rootLevel is the ultimate ancestor of  
any logger.   So the "MYLOG" logger or any logger that starts "MYLOG."  
will have an effective level of ALL (the lowest possible level) and  
any other logger will have an effective level of WARN.

If a logging requests meets or exceeds the effective level of its  
logger, then it is processed by every appender attached to the logger  
and every ancestor stopping after it reaches the rootLogger or a  
logger with additivity set to false.  The effective level of the  
intermediary loggers do not affect propagation.  The default value for  
additivity is true, so your configuration line that sets the value to  
its default, while legal, is atypical.  If you wanted logging requests  
that were sent to "MYLOG" or descendants to not be sent to appender_1,  
then you should set additivity to false.

Specifically, the propagation logic would not check that a logging  
request that propagated from MYLOG is WARN or higher.  The  
independence of the effective level and propagation allows a user to  
drop the threshold in a specific part of the logger hierarchy by  
simply inserting a lower level at the point of concern.  It would be  
very common for the rootLogger to have an INFO level and then some  
descendant to be set to DEBUG or TRACE to get more detailed info.

> Am I confusing level inheritance down to children loggers vs. filter  
> of children logs by parent loggers?  Is the latter not supported by  
> Log4j?

Could you explain the end result you'd like to achieve?

> I'm using version 1.2.15.
> Thanks for any help.
> - Howard
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message