从 log4j 1.x 迁移到 2.x.

如果要从项目中的现有 log4j 1.x 迁移到 log4j 2.x,则删除所有现有的 log4j 1.x 依赖项并添加以下依赖项:

Log4j 1.x API 桥

Maven Build

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.6.2</version>
  </dependency>
</dependencies>

常春藤建设

<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-1.2-api" rev="2.6.2" />
</dependencies>

Gradle Build

dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.6.2'
}

Apache Commons Logging Bridge 如果你的项目使用的是使用 log4j 1.x 的 Apache Commons Logging,并且你希望将其迁移到 log4j 2.x,则添加以下依赖项:

Maven Build

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
    <version>2.6.2</version>
  </dependency>
</dependencies>

常春藤建设

<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-jcl" rev="2.6.2" />
</dependencies>

Gradle Build

dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.6.2'
}

注意:不要删除 Apache commons 日志记录的任何现有依赖项

参考: https//logging.apache.org/log4j/2.x/maven-artifacts.html