logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Britton <...@hp.com>
Subject Re: Multiple Appenders additivity
Date Mon, 25 Aug 2008 15:16:19 GMT
On Fri, Aug 22, 2008 at 07:18:09AM +0000, Omer Dogan wrote:
> When i was trying to log on console with additivity, i realise log4j dont care if parent
categories have appropriate level to log the event.
> is this a design choice and are there any other way to prevent the appenders from logging
smaller level of logging events.
> Best of i can do is changing the source-code of log4j
> Scenerio
> I want to write all aplication logs to a file and
> I want to write only error logs to console
> and I dont want repeated log statements like "consolelogger.error("error 1"); filelogger.error("error

I think you should look into Log4j Filters.  Particularly the
"LevelMatchFilter" or "LevelRangeFilter".

I believe that you have a faulty assumption about the purpose of the
category/logger priorities.  They are inherited from their parent, but
if you override a priority of a child from ERROR to DEBUG, you are
telling log4j that you want to see debug messages, and you want them to
fire all the way back up the chain (unless you have defined different

Note that in order to take advantage of filters, you will need to switch
to the xml format.

Adding the following levelRangeFilter to your console appender should do
what you want:

    <appender ...>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="ERROR" />
            <param name="LevelMax" value="FATAL" />

David Britton <dpb@hp.com>

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

View raw message