xml log4j2 + slf4j的正确配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml log4j2 + slf4j的正确配置相关的知识,希望对你有一定的参考价值。

log4j的正确配置

<!--slf4j-->

<dependency>
    
<groupId>org.slf4j</groupId>

    <artifactId>slf4j-api</artifactId>

    <version>${slf4j.version}</version>

</dependency>


<!--具体log实现(jcl/jul/log4j1)到slf4j-->

<dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>jcl-over-slf4j</artifactId>

    <version>${slf4j.version}</version>

</dependency>

<dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>jul-to-slf4j</artifactId>

    <version>${slf4j.version}</version>

</dependency>

<dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>log4j-over-slf4j</artifactId>

    <version>${slf4j.version}</version>

</dependency>

<!--log4j2库-->

<dependency>

    <groupId>org.apache.logging.log4j</groupId>

    <artifactId>log4j-api</artifactId>

    <version>${log4j2.version}</version>

</dependency>

<dependency>

    <groupId>org.apache.logging.log4j</groupId>

    <artifactId>log4j-core</artifactId>

    <version>${log4j2.version}</version>

</dependency>

<!--slf4j到log4j2实现-->

<dependency>

    <groupId>org.apache.logging.log4j</groupId>

    <artifactId>log4j-slf4j-impl</artifactId>

    <version>${log4j2.version}</version>

</dependency>


<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.4</version>
  <executions>
      <execution>
          <id>enforce-versions</id>
          <goals>
              <goal>enforce</goal>
          </goals>
          <configuration>
              <rules>
                  <requireMavenVersion>
                      <version>[3.0.0,)</version>
                  </requireMavenVersion>
                  <requireJavaVersion>
                      <version>[1.8.0,)</version>
                  </requireJavaVersion>
                  <!--禁止出现 slf4j 桥接到具体 log 实现的相关 jar 包-->
                  <bannedDependencies>
                  	<searchTransitive>true</searchTransitive>
                      <excludes>
                          <include>ch.qos.logback:logback-classic</include>
                          <include>commons-logging:commons-logging</include>
                          <include>org.slf4j:slf4j-log4j12</include>
                          <include>org.slf4j:slf4j-jdk14</include>
                          <include>org.slf4j:slf4j-jcl</include>
                      </excludes>
                  </bannedDependencies>
              </rules>
          </configuration>
      </execution>
  </executions>
</plugin>

以上是关于xml log4j2 + slf4j的正确配置的主要内容,如果未能解决你的问题,请参考以下文章

log4j2配置文件详解(springboot+slf4j+log4j2+yaml+lombok)

log4j2 配置文件 log4j2.xml 详解(转载)

Java 学习笔记 - 日志体系 SLF4J + Log4j2

Java 学习笔记 - 日志体系 SLF4J + Log4j2

log4j2

【日志】Log4j2配置