logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Adding level to appender in manual code configuration in log4j2
Date Sat, 23 Sep 2017 20:05:57 GMT

> On Sep 23, 2017, at 8:11 AM, Alex Sviridov <ooo_saturn7@mail.ru.INVALID> wrote:
> 
> Hi all
> 
> From here (https://logging.apache.org/log4j/2.0/faq.html#config_sep_appender_level)
> 
>> You don’t need to declare separate loggers to achieve this. You can
>> set the logging level on the AppenderRef element.
> 
> And xml example (part):
> 
>     <Root level="trace">
>       <AppenderRef ref="file" level="DEBUG"/>
>       <AppenderRef ref="STDOUT" level="INFO"/>
>     </Root>
> 
> But I can't find a way to do it when I create configuration myself. For example I have
consoleAppenderBuilder and rootLoggerBuilder:
> 
>     AppenderComponentBuilder consoleAppenderBuilder = builder
>         .newAppender("Stdout", "CONSOLE")
>         .addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
>     
>     RootLoggerComponentBuilder rootLoggerBuilder = builder
>         .newRootLogger(Level.ERROR)
>         .add(builder.newAppenderRef("Stdout"));
> 
> Could anyone say how to add console appender to root logger and define log level for
appender?
> I am asking this because I want to add multiple appenders to root logger.
> 
> Best regards, Alex
> From  here
>> You don’t need to declare separate loggers to achieve this. You can
>> set the logging level on the AppenderRef element.
> And xml example (part):
> <Root level="trace">
>  <AppenderRef ref="file" level="DEBUG"/>
>  <AppenderRef ref="STDOUT" level="INFO"/>
> </Root>
> But I can't find a way to do it when I create configuration myself. 
> For example I have consoleAppenderBuilder and rootLoggerBuilder:
> AppenderComponentBuilder consoleAppenderBuilder = builder
>    .newAppender("Stdout", "CONSOLE")
>    .addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
> 
> RootLoggerComponentBuilder rootLoggerBuilder = builder
>    .newRootLogger(Level.ERROR)
>    .add(builder.newAppenderRef("Stdout"));
> How to add console appender to root logger and define log level for 
> appender. I am asking this because I want to add multiple appenders to 
> root logger.

I would try

AppenderRefComponentBuilder ref1 = builder.newAppenderRef(“file”).addAttribute(“level”,
“DEBUG”);
AppenderRefComponentBuilder ref2 = builder.newAppenderRef(“Stdout”).addAttribute(“level”,
“INFO”);
RootLoggerComponentBuilder rootLoggerBuilder = builder.newRootLogger(Level.ERROR).add(ref1).add(ref2)

Ralph

 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message