You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by fedinho <fe...@gmail.com> on 2013/10/01 18:17:41 UTC

Multiple appenders and verbose logging for specific classes for an appender

Hi.

A simple question I hope someone can help me with. This is using log4j 1.2.x

I would like to log info level to one appender A and warn level to another
appenderB.

However, I would like to log debug messages from class X to appender A, and
debug messages from class Y to appender B.

Thanks for any tips for a configuration that will work. Threshold is not
the way to go. Is there a way A and B can have different root loggers or
categories?

Kind regards
Fredrik

Re: Multiple appenders and verbose logging for specific classes for an appender

Posted by fedinho <fe...@gmail.com>.
Hi Jake.

Thank you for explaining this very well. My motivation for having two
separate appenders that need to be tuned independently this way, is that I
need one log file/appender for debugging/analyzing and one for monitoring.
- The debugging log can in some periods be very verbose when doing
debugging, and should be tuned without affecting the monitoring log
- The monitoring log is being indexed by a monitoring system, and there are
events/reports based on the monitoring log. Sometimes alarms/reports
require more verbose logging for some classes.

Achieving this shouldn't be so complicated, I think. I haven't had the
chance to look much into log4j2 (in beta now) and to see if there is any
simpler way of doing this (dynamic threshold might be one way to go).
However, the underlying platform currently requires log4j 1.2.x. I think it
uses slf4j facade, though, so maybe log4j2 would be possible.

Thanks again,
Fredrik



On Wed, Oct 2, 2013 at 6:25 PM, Jacob Kjome <ho...@visi.com> wrote:

>
> Apply appenderA and AppenderB to the root logger.  I always set the root
> logger level to WARN to avoid trace/debug/info messages from arbitrary
> libraries.
>
> Then, if you want INFO logging for most of your library, configure the
> lowest common denominator package for your app, let's say "com.myapp", for
> the INFO level.
>
> Now configure the ClassX and ClassY loggers for the DEBUG level.
>
> Now your requirements get complicated.  You need to configure filters for
> both appenders so that:
>
> 1. AppenderB explicitly ignores anything but WARN+, except when logging
> for ClassY, in which case it should accept DEBUG+.
> 2. AppenderA accepts whatever is sent to it except when logging for
> ClassY, in which case it should only accept INFO+
>
> You can roll your own filter by implementing the Filter interface [1] or
> you could try the extras [2] ExpressionFilter [3].  I'm not an expert on
> supported expressions, but you can search for examples, such as [4].
>
> This is an awfully complicated setup.  I hope this is just about theory
> and not the way you actually intend to use Log4j.  Nevertheless, Log4j
> should be able to handle it.
>
>
> [1] http://logging.apache.org/**log4j/1.2/apidocs/org/apache/**
> log4j/spi/Filter.html<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html>
> [2] http://logging.apache.org/**log4j/companions/extras/index.**html<http://logging.apache.org/log4j/companions/extras/index.html>
> [3] http://svn.apache.org/repos/**asf/logging/site/trunk/docs/**
> log4j/companions/extras/**apidocs/org/apache/log4j/**
> filter/ExpressionFilter.html<http://svn.apache.org/repos/asf/logging/site/trunk/docs/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html>
> [4] http://apache-logging.6191.n7.**nabble.com/Multiple-**
> expressions-define-in-one-**ExpressionFilter-td7229.html<http://apache-logging.6191.n7.nabble.com/Multiple-expressions-define-in-one-ExpressionFilter-td7229.html>
>
>
> Jake
>
>
> On Wed, 2 Oct 2013 11:16:42 +0200
>  fedinho <fe...@gmail.com> wrote:
>
>> Hi.
>>
>> No, I do not want to exclude the more severe logging levels, but I want to
>> enable more verbose logging for specific classes for appender A
>> independently of appender Bs logging of those same classes, and vice
>> versa:
>>
>> Appender A and B is defined.
>> Appender A is logging INFO+ for all by default, while appender B is
>> logging
>> WARN+ for all.
>> Class X is logging DEBUG+more severe levels through appender A, but still
>> logging WARN+more severe levels through appender B.
>> Class Y is logging DEBUG+more severe levels through appender B, but still
>> logging INFO+more severe levels through appender A.
>> + means including more severe logging levels
>>
>> Thanks
>> Fredrik
>>
>>
>> On Wed, Oct 2, 2013 at 9:35 AM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>  By default, if you set the level of a logger/appender to debug, it will
>>> process debug, info, warn, error and fatal messages.
>>>
>>> Is this what you want, or do you want to include only debug-level
>>> messages,
>>> and exclude info, warn, error and fatal messages?
>>>
>>> On Wednesday, October 2, 2013, fedinho wrote:
>>>
>>> > Thanks for your response Jacob.
>>> >
>>> > I've been looking at the additive feature, but I'm not sure it solves
>>> my
>>> > requirement.
>>> >
>>> > Given this configuration, I would like to debug class X on appender A,
>>> but
>>> > still keep the info level messages from class X on appender B.
>>> >
>>> > I was hoping that this line would make this happen, but doesn't seem to
>>> > work.
>>> > log4j.logger.classX=debug, A
>>> >
>>> > Is there a simple example similar to my requirements somewhere?
>>> >
>>> > Thanks
>>> > Fredrik
>>> >
>>> >
>>> > On Tue, Oct 1, 2013 at 6:50 PM, Jacob Kjome <hoju@visi.com
>>> <javascript:;>>
>>> > wrote:
>>> >
>>> > > On Tue, 1 Oct 2013 18:17:41 +0200
>>> > >  fedinho <fedinho@gmail.com <javascript:;>> wrote:
>>> > >
>>> > >> Hi.
>>> > >>
>>> > >> A simple question I hope someone can help me with. This is using
>>> log4j
>>> > >> 1.2.x
>>> > >>
>>> > >> I would like to log info level to one appender A and warn level to
>>> > another
>>> > >> appenderB.
>>> > >>
>>> > >> However, I would like to log debug messages from class X to appender
>>> A,
>>> > >> and
>>> > >> debug messages from class Y to appender B.
>>> > >>
>>> > >> Thanks for any tips for a configuration that will work. Threshold is
>>> not
>>> > >> the way to go. Is there a way A and B can have different root
>>> loggers
>>> or
>>> > >> categories?
>>> > >>
>>> > >>
>>> > > This is usually done by setting the logger additivity to "false" for
>>> > > either the logger in question or one it inherits from, which
>>> essentially
>>> > > makes the logger with additivity=false the root logger for all
>>> > inheritors.
>>> > > See...
>>> > >
>>> > >
>>> >
>>> http://logging.apache.org/****log4j/1.2/manual.html#****
>>> Appenders_and_Layouts<http://logging.apache.org/**log4j/1.2/manual.html#**Appenders_and_Layouts>
>>> <
>>> > http://logging.apache.org/**log4j/1.2/manual.html#**
>>> Appenders_and_Layouts<http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts>
>>> >
>>> > >
>>> > >
>>> > >  Kind regards
>>> > >> Fredrik
>>> > >>
>>> > >
>>> > >
>>> > >
>>> ------------------------------****----------------------------**
>>> --**---------
>>> > > To unsubscribe, e-mail: log4j-user-unsubscribe@**loggi**
>>> ng.apache.org <http://logging.apache.org><
>>> > log4j-user-unsubscribe@**logging.apache.org<lo...@logging.apache.org><javascript:;>>
>>> > > For additional commands, e-mail: log4j-user-help@logging.**apac**
>>> he.org <http://apache.org><
>>> > log4j-user-help@logging.**apache.org<lo...@logging.apache.org><javascript:;>>
>>> > >
>>> > >
>>> >
>>>
>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<lo...@logging.apache.org>
> For additional commands, e-mail: log4j-user-help@logging.**apache.org<lo...@logging.apache.org>
>
>

Re: Multiple appenders and verbose logging for specific classes for an appender

Posted by Jacob Kjome <ho...@visi.com>.
Apply appenderA and AppenderB to the root logger.  I always set the root 
logger level to WARN to avoid trace/debug/info messages from arbitrary 
libraries.

Then, if you want INFO logging for most of your library, configure the lowest 
common denominator package for your app, let's say "com.myapp", for the INFO 
level.

Now configure the ClassX and ClassY loggers for the DEBUG level.

Now your requirements get complicated.  You need to configure filters for both 
appenders so that:

1. AppenderB explicitly ignores anything but WARN+, except when logging for 
ClassY, in which case it should accept DEBUG+.
2. AppenderA accepts whatever is sent to it except when logging for ClassY, in 
which case it should only accept INFO+

You can roll your own filter by implementing the Filter interface [1] or you 
could try the extras [2] ExpressionFilter [3].  I'm not an expert on supported 
expressions, but you can search for examples, such as [4].

This is an awfully complicated setup.  I hope this is just about theory and 
not the way you actually intend to use Log4j.  Nevertheless, Log4j should be 
able to handle it.


[1] 
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html
[2] http://logging.apache.org/log4j/companions/extras/index.html
[3] 
http://svn.apache.org/repos/asf/logging/site/trunk/docs/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html
[4] 
http://apache-logging.6191.n7.nabble.com/Multiple-expressions-define-in-one-ExpressionFilter-td7229.html


Jake

On Wed, 2 Oct 2013 11:16:42 +0200
 fedinho <fe...@gmail.com> wrote:
> Hi.
> 
> No, I do not want to exclude the more severe logging levels, but I want to
> enable more verbose logging for specific classes for appender A
> independently of appender Bs logging of those same classes, and vice versa:
> 
> Appender A and B is defined.
> Appender A is logging INFO+ for all by default, while appender B is logging
> WARN+ for all.
> Class X is logging DEBUG+more severe levels through appender A, but still
> logging WARN+more severe levels through appender B.
> Class Y is logging DEBUG+more severe levels through appender B, but still
> logging INFO+more severe levels through appender A.
> + means including more severe logging levels
> 
> Thanks
>Fredrik
> 
> 
> On Wed, Oct 2, 2013 at 9:35 AM, Remko Popma <re...@gmail.com> wrote:
> 
>> By default, if you set the level of a logger/appender to debug, it will
>> process debug, info, warn, error and fatal messages.
>>
>> Is this what you want, or do you want to include only debug-level messages,
>> and exclude info, warn, error and fatal messages?
>>
>> On Wednesday, October 2, 2013, fedinho wrote:
>>
>> > Thanks for your response Jacob.
>> >
>> > I've been looking at the additive feature, but I'm not sure it solves my
>> > requirement.
>> >
>> > Given this configuration, I would like to debug class X on appender A,
>> but
>> > still keep the info level messages from class X on appender B.
>> >
>> > I was hoping that this line would make this happen, but doesn't seem to
>> > work.
>> > log4j.logger.classX=debug, A
>> >
>> > Is there a simple example similar to my requirements somewhere?
>> >
>> > Thanks
>> > Fredrik
>> >
>> >
>> > On Tue, Oct 1, 2013 at 6:50 PM, Jacob Kjome <hoju@visi.com<javascript:;>>
>> > wrote:
>> >
>> > > On Tue, 1 Oct 2013 18:17:41 +0200
>> > >  fedinho <fedinho@gmail.com <javascript:;>> wrote:
>> > >
>> > >> Hi.
>> > >>
>> > >> A simple question I hope someone can help me with. This is using log4j
>> > >> 1.2.x
>> > >>
>> > >> I would like to log info level to one appender A and warn level to
>> > another
>> > >> appenderB.
>> > >>
>> > >> However, I would like to log debug messages from class X to appender
>> A,
>> > >> and
>> > >> debug messages from class Y to appender B.
>> > >>
>> > >> Thanks for any tips for a configuration that will work. Threshold is
>> not
>> > >> the way to go. Is there a way A and B can have different root loggers
>> or
>> > >> categories?
>> > >>
>> > >>
>> > > This is usually done by setting the logger additivity to "false" for
>> > > either the logger in question or one it inherits from, which
>> essentially
>> > > makes the logger with additivity=false the root logger for all
>> > inheritors.
>> > > See...
>> > >
>> > >
>> >
>> http://logging.apache.org/**log4j/1.2/manual.html#**Appenders_and_Layouts<
>> > http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts>
>> > >
>> > >
>> > >  Kind regards
>> > >> Fredrik
>> > >>
>> > >
>> > >
>> > >
>> ------------------------------**------------------------------**---------
>> > > To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<
>> > log4j-user-unsubscribe@logging.apache.org <javascript:;>>
>> > > For additional commands, e-mail: log4j-user-help@logging.**apache.org<
>> > log4j-user-help@logging.apache.org <javascript:;>>
>> > >
>> > >
>> >
>>


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


Re: Multiple appenders and verbose logging for specific classes for an appender

Posted by fedinho <fe...@gmail.com>.
Hi.

No, I do not want to exclude the more severe logging levels, but I want to
enable more verbose logging for specific classes for appender A
independently of appender Bs logging of those same classes, and vice versa:

Appender A and B is defined.
Appender A is logging INFO+ for all by default, while appender B is logging
WARN+ for all.
Class X is logging DEBUG+more severe levels through appender A, but still
logging WARN+more severe levels through appender B.
Class Y is logging DEBUG+more severe levels through appender B, but still
logging INFO+more severe levels through appender A.
+ means including more severe logging levels

Thanks
Fredrik


On Wed, Oct 2, 2013 at 9:35 AM, Remko Popma <re...@gmail.com> wrote:

> By default, if you set the level of a logger/appender to debug, it will
> process debug, info, warn, error and fatal messages.
>
> Is this what you want, or do you want to include only debug-level messages,
> and exclude info, warn, error and fatal messages?
>
> On Wednesday, October 2, 2013, fedinho wrote:
>
> > Thanks for your response Jacob.
> >
> > I've been looking at the additive feature, but I'm not sure it solves my
> > requirement.
> >
> > Given this configuration, I would like to debug class X on appender A,
> but
> > still keep the info level messages from class X on appender B.
> >
> > I was hoping that this line would make this happen, but doesn't seem to
> > work.
> > log4j.logger.classX=debug, A
> >
> > Is there a simple example similar to my requirements somewhere?
> >
> > Thanks
> > Fredrik
> >
> >
> > On Tue, Oct 1, 2013 at 6:50 PM, Jacob Kjome <hoju@visi.com<javascript:;>>
> > wrote:
> >
> > > On Tue, 1 Oct 2013 18:17:41 +0200
> > >  fedinho <fedinho@gmail.com <javascript:;>> wrote:
> > >
> > >> Hi.
> > >>
> > >> A simple question I hope someone can help me with. This is using log4j
> > >> 1.2.x
> > >>
> > >> I would like to log info level to one appender A and warn level to
> > another
> > >> appenderB.
> > >>
> > >> However, I would like to log debug messages from class X to appender
> A,
> > >> and
> > >> debug messages from class Y to appender B.
> > >>
> > >> Thanks for any tips for a configuration that will work. Threshold is
> not
> > >> the way to go. Is there a way A and B can have different root loggers
> or
> > >> categories?
> > >>
> > >>
> > > This is usually done by setting the logger additivity to "false" for
> > > either the logger in question or one it inherits from, which
> essentially
> > > makes the logger with additivity=false the root logger for all
> > inheritors.
> > > See...
> > >
> > >
> >
> http://logging.apache.org/**log4j/1.2/manual.html#**Appenders_and_Layouts<
> > http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts>
> > >
> > >
> > >  Kind regards
> > >> Fredrik
> > >>
> > >
> > >
> > >
> ------------------------------**------------------------------**---------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<
> > log4j-user-unsubscribe@logging.apache.org <javascript:;>>
> > > For additional commands, e-mail: log4j-user-help@logging.**apache.org<
> > log4j-user-help@logging.apache.org <javascript:;>>
> > >
> > >
> >
>

Re: Multiple appenders and verbose logging for specific classes for an appender

Posted by Remko Popma <re...@gmail.com>.
By default, if you set the level of a logger/appender to debug, it will
process debug, info, warn, error and fatal messages.

Is this what you want, or do you want to include only debug-level messages,
and exclude info, warn, error and fatal messages?

On Wednesday, October 2, 2013, fedinho wrote:

> Thanks for your response Jacob.
>
> I've been looking at the additive feature, but I'm not sure it solves my
> requirement.
>
> Given this configuration, I would like to debug class X on appender A, but
> still keep the info level messages from class X on appender B.
>
> I was hoping that this line would make this happen, but doesn't seem to
> work.
> log4j.logger.classX=debug, A
>
> Is there a simple example similar to my requirements somewhere?
>
> Thanks
> Fredrik
>
>
> On Tue, Oct 1, 2013 at 6:50 PM, Jacob Kjome <hoju@visi.com <javascript:;>>
> wrote:
>
> > On Tue, 1 Oct 2013 18:17:41 +0200
> >  fedinho <fedinho@gmail.com <javascript:;>> wrote:
> >
> >> Hi.
> >>
> >> A simple question I hope someone can help me with. This is using log4j
> >> 1.2.x
> >>
> >> I would like to log info level to one appender A and warn level to
> another
> >> appenderB.
> >>
> >> However, I would like to log debug messages from class X to appender A,
> >> and
> >> debug messages from class Y to appender B.
> >>
> >> Thanks for any tips for a configuration that will work. Threshold is not
> >> the way to go. Is there a way A and B can have different root loggers or
> >> categories?
> >>
> >>
> > This is usually done by setting the logger additivity to "false" for
> > either the logger in question or one it inherits from, which essentially
> > makes the logger with additivity=false the root logger for all
> inheritors.
> > See...
> >
> >
> http://logging.apache.org/**log4j/1.2/manual.html#**Appenders_and_Layouts<
> http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts>
> >
> >
> >  Kind regards
> >> Fredrik
> >>
> >
> >
> > ------------------------------**------------------------------**---------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<
> log4j-user-unsubscribe@logging.apache.org <javascript:;>>
> > For additional commands, e-mail: log4j-user-help@logging.**apache.org<
> log4j-user-help@logging.apache.org <javascript:;>>
> >
> >
>

Re: Multiple appenders and verbose logging for specific classes for an appender

Posted by fedinho <fe...@gmail.com>.
Thanks for your response Jacob.

I've been looking at the additive feature, but I'm not sure it solves my
requirement.

Given this configuration, I would like to debug class X on appender A, but
still keep the info level messages from class X on appender B.

I was hoping that this line would make this happen, but doesn't seem to
work.
log4j.logger.classX=debug, A

Is there a simple example similar to my requirements somewhere?

Thanks
Fredrik


On Tue, Oct 1, 2013 at 6:50 PM, Jacob Kjome <ho...@visi.com> wrote:

> On Tue, 1 Oct 2013 18:17:41 +0200
>  fedinho <fe...@gmail.com> wrote:
>
>> Hi.
>>
>> A simple question I hope someone can help me with. This is using log4j
>> 1.2.x
>>
>> I would like to log info level to one appender A and warn level to another
>> appenderB.
>>
>> However, I would like to log debug messages from class X to appender A,
>> and
>> debug messages from class Y to appender B.
>>
>> Thanks for any tips for a configuration that will work. Threshold is not
>> the way to go. Is there a way A and B can have different root loggers or
>> categories?
>>
>>
> This is usually done by setting the logger additivity to "false" for
> either the logger in question or one it inherits from, which essentially
> makes the logger with additivity=false the root logger for all inheritors.
> See...
>
> http://logging.apache.org/**log4j/1.2/manual.html#**Appenders_and_Layouts<http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts>
>
>
>  Kind regards
>> Fredrik
>>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<lo...@logging.apache.org>
> For additional commands, e-mail: log4j-user-help@logging.**apache.org<lo...@logging.apache.org>
>
>

Re: Multiple appenders and verbose logging for specific classes for an appender

Posted by Jacob Kjome <ho...@visi.com>.
On Tue, 1 Oct 2013 18:17:41 +0200
 fedinho <fe...@gmail.com> wrote:
> Hi.
> 
> A simple question I hope someone can help me with. This is using log4j 1.2.x
> 
> I would like to log info level to one appender A and warn level to another
> appenderB.
> 
> However, I would like to log debug messages from class X to appender A, and
> debug messages from class Y to appender B.
> 
> Thanks for any tips for a configuration that will work. Threshold is not
> the way to go. Is there a way A and B can have different root loggers or
> categories?
> 

This is usually done by setting the logger additivity to "false" for either 
the logger in question or one it inherits from, which essentially makes the 
logger with additivity=false the root logger for all inheritors.  See...

http://logging.apache.org/log4j/1.2/manual.html#Appenders_and_Layouts


> Kind regards
>Fredrik


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