Java 升级log4j 到 log4j2 (web工程,springboot工程,非maven工程)

  1. Java web(SSH)
    (1) web.xml:
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:config/log4j.properties</param-value>
  </context-param>
  // 修改为
  <context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>classpath:config/log4j2.xml</param-value>
  </context-param>

(2) jar包
WebRoot/WEB-INF/lib/slf4j-api-1.7.7.jar -----------不变
WebRoot/WEB-INF/lib/log4j-1.2.15.jar ----------- 删除
WebRoot/WEB-INF/lib/log4j-api-2.12.1.jar -----------增加
WebRoot/WEB-INF/lib/log4j-core-2.12.1.jar ----------- 增加
WebRoot/WEB-INF/lib/log4j-slf4j-impl-2.12.1.jar ----------- 增加
WebRoot/WEB-INF/lib/log4j-web-2.12.1.jar -----------增加
WebRoot/WEB-INF/lib/slf4j-log4j12-1.7.7.jar ----------- 删除

(3) log4j配置文件
log4j.properties => log4j2.xml

  1. Springboot
    (1)maven依赖
   <dependency>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-log4j</artifactId>
	</dependency>
  // 修改为
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-log4j2</artifactId>
   </dependency>

(2) log4j配置文件
log4j.properties => log4j2.xml

你可能感兴趣的:(Java 升级log4j 到 log4j2 (web工程,springboot工程,非maven工程))