Setting different log levels to different appenders for a specific package (logger)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting different log levels to different appenders for a specific package (logger)

Asma Zinneera Jabir
I want package com.abc.xyz to log only ERRORs to the console and INFO and
above to a file. How do I give the configuration in log4j2.xml for this?
Tried doing the below but didn't work.

<Loggers>
<Root level="info">
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="LOGFILE"/>
</Root>

<Logger name="com.abc.xyz">
     <AppenderRef ref="LOGFILE" level="info"/>
     <AppenderRef ref="CONSOLE" level="error" />
    </Logger>
</Loggers>
Reply | Threaded
Open this post in threaded view
|

Re: Setting different log levels to different appenders for a specific package (logger)

Matt Sicker
I don't remember if there's a simpler way to do it, but the advanced way of
doing this would be using a RoutingAppender which delegates to those two
different appender refs you have.

You can also take a look at additivity which is related to what you're
asking about.

On 7 December 2017 at 06:10, Asma Zinneera Jabir <[hidden email]>
wrote:

> I want package com.abc.xyz to log only ERRORs to the console and INFO and
> above to a file. How do I give the configuration in log4j2.xml for this?
> Tried doing the below but didn't work.
>
> <Loggers>
> <Root level="info">
> <AppenderRef ref="CONSOLE"/>
> <AppenderRef ref="LOGFILE"/>
> </Root>
>
> <Logger name="com.abc.xyz">
>      <AppenderRef ref="LOGFILE" level="info"/>
>      <AppenderRef ref="CONSOLE" level="error" />
>     </Logger>
> </Loggers>
>



--
Matt Sicker <[hidden email]>