Re: Adding level to appender in manual code configuration in log4j2

2017-09-23 Thread Ralph Goers

> On Sep 23, 2017, at 8:11 AM, Alex Sviridov  
> 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):
> 
> 
>   
>   
> 
> 
> 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):
> 
>  
>  
> 
> 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-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: log4j2.xml won't get read

2017-09-23 Thread Mikael Ståldal
I don't know how Wildfly works, but maybe you should ask this question 
to any support forum of Wildfly.



On 2017-09-19 13:16, Christian Wansart wrote:

Hello,

I am working on a jax-rs project that uses log4j through slf4j-api and 
log4j-slf4j-impl. So far, I configured the logging pattern via Wildfly’s 
standalone.xml. But I want to have a project wide config file for logging.

I put a log4j2.xml in the resources folder, but when I run it, it just uses the 
pattern of the standalone.xml.

Here is my log4j2.xml:

   
   
 
   
 
   
 
 
   
 
   
 
   

What am I missing? It seems that the file was not read?  In the output in my 
IntelliJ IDEA IDE I just see the log messages in the format I set in the 
standalone.xml.

Best regards,
Christian


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




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



Adding level to appender in manual code configuration in log4j2

2017-09-23 Thread Alex Sviridov
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):

    
  
  
    

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):

  
  

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.