我是靠谱客的博主 炙热百褶裙,最近开发中收集的这篇文章主要介绍springMvc:log4j平滑升级log4j21: 删除原有依赖2: 新建依赖3: 修改 webapp/WEB_INF/lib/web.xml4: 创建resources/log4j2.xml,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
springMvc:log4j平滑升级log4j2
- 1: 删除原有依赖
- 2: 新建依赖
- 3: 修改 webapp/WEB_INF/lib/web.xml
- 4: 创建resources/log4j2.xml
1: 删除原有依赖
<!--
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
-->
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j-nop.version}</version>
</dependency>
-->
2: 新建依赖
<!-- log4j2依赖包 -->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.0</version>
</dependency>
<!-- log4j2核心包 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
</dependency>
<!-- 该包是 log4j 升级到 log4j2的必须包 使用该包 不需要修改以前的 Logger.getLogger()这种获取对象的方式 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.8</version>
</dependency>
<!-- 该包是slf4j 升级到 log4j2的必须包 使用该包 其他依赖jar中依赖slf4j 不会报错 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8</version>
</dependency>
3: 修改 webapp/WEB_INF/lib/web.xml
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<!--去掉.properties-->
<!--<param-value>classpath:log4j.properties</param-value>-->
<!--新增.xml-->
<param-value>classpath:log4j2.xml</param-value>
</context-param>
4: 创建resources/log4j2.xml
并备份和删除原先的log4j.properties
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="info">
<Properties>
<!--注意,这个路径要指向 /home/admin/${APP_NAME}/logs -->
<Property name="catalina_path">${catalina.base}</Property>
</Properties>
<appenders>
<Console name="CONSOLE" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%dt[%t]t%-5pt%C.%M(%L)t${hostName}***%m%n"/>
</Console>
<RollingRandomAccessFile name="CATALINA_APPENDER" fileName="${catalina.base}/catalina.out"
immediateFlush="false"
filePattern="${catalina.base}/catalina.out.%d{yyyy-MM-dd-HH}.log">
<Filters>
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<PatternLayout pattern="%d [%t] %-5p %C.%M(%L)- %m%n" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<!--<SizeBasedTriggeringPolicy size="1000 MB"/>-->
</Policies>
<!-- 去掉默认的滚动策略 -->
<DefaultRolloverStrategy/>
<!--max 保留最大天数 默认 10天,lazy=true 每次只检测1个文件进行删除。lazy=false 会递归删除-->
<!--<MaxDayFileRolloverStrategy max="15" lazy="true"/>-->
</RollingRandomAccessFile>
<RollingRandomAccessFile name="DEBUG_APPENDER" fileName="${catalina.base}/debug.out"
immediateFlush="false"
filePattern="${catalina.base}/debug.out.%d{yyyy-MM-dd}.log">
<Filters>
<ThresholdFilter level="info" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<PatternLayout pattern="%d [%t] %-5p %C.%M(%L)- %m%n" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<!--<SizeBasedTriggeringPolicy size="1000 MB"/>-->
</Policies>
<!-- 去掉默认的滚动策略 -->
<DefaultRolloverStrategy/>
<!--max 保留最大天数 默认 10天,lazy=true 每次只检测1个文件进行删除。lazy=false 会递归删除-->
<!--<MaxDayFileRolloverStrategy max="15" lazy="true"/>-->
</RollingRandomAccessFile>
<RollingRandomAccessFile name="WARN_APPENDER" fileName="${catalina.base}/warn.out"
immediateFlush="false"
filePattern="${catalina.base}/warn.out.%d{yyyy-MM-dd}.log">
<Filters>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<PatternLayout pattern="%d [%t] %-5p %C.%M(%L)- %m%n" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<!--<SizeBasedTriggeringPolicy size="1000 MB"/>-->
</Policies>
<!-- 去掉默认的滚动策略 -->
<DefaultRolloverStrategy/>
<!--max 保留最大天数 默认 10天,lazy=true 每次只检测1个文件进行删除。lazy=false 会递归删除-->
<!--<MaxDayFileRolloverStrategy max="15" lazy="true"/>-->
</RollingRandomAccessFile>
<RollingRandomAccessFile name="ERROR_APPENDER" fileName="${catalina.base}/error.out"
immediateFlush="false"
filePattern="${catalina.base}/error.out.%d{yyyy-MM-dd}.log">
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%d [%t] %-5p %C.%M(%L)- %m%n" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<!--<SizeBasedTriggeringPolicy size="1000 MB"/>-->
</Policies>
<!-- 去掉默认的滚动策略 -->
<DefaultRolloverStrategy/>
<!--max 保留最大天数 默认 10天,lazy=true 每次只检测1个文件进行删除。lazy=false 会递归删除-->
<!--<MaxDayFileRolloverStrategy max="15" lazy="true"/>-->
</RollingRandomAccessFile>
<RollingRandomAccessFile name="STATISTICLOG_APPENDER" fileName="${catalina.base}/am_raw_mist_access"
immediateFlush="false"
filePattern="${catalina.base}/am_raw_mist_access.%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d [%t] %-5p %C.%M(%L)- %m%n" charset="UTF-8"/>
<Filters>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy/>
<!--<SizeBasedTriggeringPolicy size="1000 MB"/>-->
</Policies>
<!-- 去掉默认的滚动策略 -->
<DefaultRolloverStrategy/>
<!--max 保留最大天数 默认 10天,lazy=true 每次只检测1个文件进行删除。lazy=false 会递归删除-->
<MaxDayFileRolloverStrategy max="93" lazy="true"/>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="CHARGE_APPENDER" fileName="${catalina.base}/charge_log"
immediateFlush="false"
filePattern="${catalina.base}/charge_log.%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d [%t] %-5p %C.%M(%L)- %m%n" charset="UTF-8"/>
<Filters>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<TimeBasedTriggeringPolicy/>
<!--<SizeBasedTriggeringPolicy size="1000 MB"/>-->
</Policies>
<!-- 去掉默认的滚动策略 -->
<DefaultRolloverStrategy/>
<!--max 保留最大天数 默认 10天,lazy=true 每次只检测1个文件进行删除。lazy=false 会递归删除-->
<MaxDayFileRolloverStrategy max="93" lazy="true"/>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="AM_BUSI_TRACER_APPENDER" fileName="${catalina_path}/am_busi_tracer.out"
immediateFlush="false"
filePattern="${catalina_path}/am_busi_tracer.out.%d{yyyy-MM-dd-HH}.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss}***%t***%p***%m%n" charset="UTF-8" />
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
<DefaultRolloverStrategy/>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="AM_HTTP_TRACER_APPENDER" fileName="${catalina_path}/am_http_tracer.out"
immediateFlush="false"
filePattern="${catalina_path}/am_http_tracer.out.%d{yyyy-MM-dd-HH}.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss}***%t***%p***%m%n" charset="UTF-8" />
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
<DefaultRolloverStrategy/>
</RollingRandomAccessFile>
</appenders>
<loggers>
<AsyncRoot level="info" includeLocation="true">
<AppenderRef ref="WARN_APPENDER"/>
<AppenderRef ref="ERROR_APPENDER"/>
</AsyncRoot>
<AsyncLogger name="com.alxx.lbp.mist" level="info" includeLocation="true" additivity="false">
<AppenderRef ref="DEBUG_APPENDER"/>
<AppenderRef ref="CATALINA_APPENDER"/>
<AppenderRef ref="WARN_APPENDER"/>
<AppenderRef ref="ERROR_APPENDER"/>
</AsyncLogger>
<AsyncLogger name="CHARGE" level="info" includeLocation="false" additivity="false">
<AppenderRef ref="CHARGE_APPENDER" />
</AsyncLogger>
<AsyncLogger name="STATISTICLOG" level="info" includeLocation="false" additivity="false">
<AppenderRef ref="STATISTICLOG_APPENDER" />
</AsyncLogger>
<AsyncLogger name="AM_BUSI_TRACER" level="info" includeLocation="false" additivity="false">
<AppenderRef ref="AM_BUSI_TRACER_APPENDER" />
</AsyncLogger>
<AsyncLogger name="AM_HTTP_TRACER" level="info" includeLocation="false" additivity="false">
<AppenderRef ref="AM_HTTP_TRACER_APPENDER" />
</AsyncLogger>
</loggers>
</configuration>
参考:
https://blog.csdn.net/zouxucong/article/details/56013053 《log4j升级为log4j2(不需要改动代码)》
https://blog.csdn.net/chushoutaizhong/article/details/79805774 《工程中将log4j平滑升级到log4j2(坎坷路但不是太坎坷)》
最后
以上就是炙热百褶裙为你收集整理的springMvc:log4j平滑升级log4j21: 删除原有依赖2: 新建依赖3: 修改 webapp/WEB_INF/lib/web.xml4: 创建resources/log4j2.xml的全部内容,希望文章能够帮你解决springMvc:log4j平滑升级log4j21: 删除原有依赖2: 新建依赖3: 修改 webapp/WEB_INF/lib/web.xml4: 创建resources/log4j2.xml所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复