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 Asma Zinneera Jabir <az...@gmail.com> on 2017/12/07 12:10:06 UTC

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

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>

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

Posted by Matt Sicker <bo...@gmail.com>.
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 <az...@gmail.com>
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 <bo...@gmail.com>