[logback-user] Different Log Levels For Different Appenders?

Rob Ross rob.ross at gmail.com
Thu Aug 28 16:53:33 CEST 2008


I also wanted to do exactly what you are trying to do. I discovered  
the only way to do this is with a filter on the appender, instead of  
being able to set the Level on the appender as you could do with log4j.

I don't know yet which method is "better", but the ability to set a  
filter on the appender does give me the same end-result as with  
log4j, so I am satisfied with this method.


Rob Ross, Lead Software Engineer
E! Networks

---------------------------------------------------
"Beware of he who would deny you access to information, for in his  
heart he dreams himself your master." -- Commissioner Pravin Lal



On Aug 28, 2008, at 7:01 AM, Eric Faden wrote:

> That doesn't exactly solve what I am trying to do.  The problem isn't
> that I can't get the correct level on a specific logger, the  
> problem is
> more that I want to have a specific logger go to two different  
> appenders
> and log at different levels based on the appender.  For example I want
> to have the root logger log at level INFO to the Console.  I then want
> to have the logger for some class Blah log to the appender for root
> (Console) at the level of root (INFO), but also log to a file  
> Foo.txt at
> level Debug.  So far as I can tell the only way to do this is to  
> set the
> level of Blah to debug, have a file appender, and also put a filter on
> the console appender to filter out things below INFO.  Does that make
> sense what I am trying to do?  Basically I want a single logger to log
> to different levels to different appenders.
>
> -Eric
>
> Ceki Gulcu wrote:
>> Hello Eric,
>>
>> I think this is described in chapter 3 of the manual. See "Example  
>> 3.9: Logger
>> level sample (logback-examples/src/main/java/chapter3/ 
>> sample4.xml)". The list
>> numbering in that chapter only works with Firefox. So on other  
>> browsers you
>> might see all examples numbered as "3.". See also the next section  
>> in the same
>> chapter, on "Configuring Appenders", in particular, the cumulative  
>> addition of
>> appenders. It might be the other "cleaner" way, you are looking for.
>>
>> HTH,
>>
>> Eric Faden wrote:
>>
>>> So suppose I set my root logger to error, but I want to have another
>>> logger operate at debug level.  When I do that it makes that loggers
>>> level debug for all appenders.  For example take the following
>>>
>>> <configuration>
>>>
>>>   <appender name="*FILE*"
>>>      ....
>>>   </appender>
>>>
>>>   <appender name="*STDOUT*"
>>>      ...
>>>   </appender>
>>>
>>>   <logger name="mylogger">
>>>     <level value="debug" />
>>> **    <appender-ref ref="FILE" />**
>>>   </logger>
>>>
>>>   <root>
>>>     <level value="error" />*
>>>     <appender-ref ref="STDOUT" />*
>>>   </root>
>>> </configuration>
>>>
>>> In this example mylogger would output at debug level to BOTH STDOUT
>>> and FILE.  Is it possible to only get mylogger to output at debug
>>> level to FILE and error to STDOUT?  I realize that I can add a  
>>> filter
>>> to the STDOUT appender to filter anything below ERROR, but I was
>>> curious if there was another way to do this, possibly cleaner?
>>>
>>> -Eric
>>>
>>
>>
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list