maven-log4j2 configuration

1. maven project to add dependencies

  <dependencies>
   <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.12.0</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.12.0</version>
  </dependency>
  </dependencies>
2. Add log4j2 configuration files, directories below
3. profile name log4j2.xml, reads 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="info">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>
 
4. 5 test configuration and print the results.
5. refer to the official documentation connected:
https://logging.apache.org/log4j/2.x/manual/configuration.html 

Guess you like

Origin www.cnblogs.com/live-for-learning/p/11080048.html