How to use different levels of logging for different classes using log4j2?

In the documentation log4j2 log4j2 java configuration, the default setting is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

This will result in registration for the ERROR or FATAL levels on the console. My default log works in the same way. The problem I am facing is when I do this:

<logger name="com.foo.Bar" level="TRACE"/>
<Root level="ERROR">
  <AppenderRef ref="STDOUT">
</Root>

According to the documentation, log4j2 java configuration , this will be

exclude all TRACE output from everything except com.foo.Bar.

My implementation, on the other hand, works as if

<logger name="com.foo.Bar" level="TRACE"/>

there wasn’t even. It will only print error logs anyway.

Questions

  • Has anyone else encountered this problem?
  • Can anyone reproduce it?
  • - , ? - . , , .

:

Maven

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.0-beta9</version>
      </dependency>
      <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0-beta9</version>
      </dependency>
    <dependency>

. JUnit. src/main.xml, src/test.xml. .

, SMTP-. , , , .

+4
1

, . , :

enter image description hereenter image description here

, .

+3

All Articles