[logback-user] Can I have level specific patterns?

Ceki Gülcü ceki at qos.ch
Fri Apr 10 23:58:24 CEST 2015


There is no out-of-the-box support for level-specific patterns in 
logback at this time.

You could of course write your own layout which does what you describe.
See http://logback.qos.ch/manual/layouts.html#writingYourOwnLayout
for documentation on this topic.

Alternatively, you could write a custom conversion specifier. If you had 
a specifier called %debug which output contents only for level DEBUG, 
and a %warn specifier which output contents only for level WARN and 
another specifier %ERROR which output contents for ERROR, your pattern 
could be written as

%debug(%level %d %t) %error(%level) %info(%level) %m%n

See http://logback.qos.ch/manual/layouts.html#customConversionSpecifier
for documentation on this topic.



On 4/10/2015 21:36, Andrew E. Davidson wrote:
> Is it possible to have a logbook-text.xml file that defines two different patterns? For example
>
> if the level is debug, I want the level, time stamp, thread, file, line number, and message.
>
> If the level is error or warn, I want the level and message
>
> If the level is info I just want the message
>
> Thanks
>
> Andy


More information about the Logback-user mailing list