logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Sviridov <ooo_satu...@mail.ru.INVALID>
Subject Adding level to appender in manual code configuration in log4j2
Date Sat, 23 Sep 2017 15:11:54 GMT
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.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message