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

Eric Faden eric at techeminence.com
Thu Aug 28 16:01:31 CEST 2008


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
>>     
>
>   



More information about the Logback-user mailing list