标签:log4j2 slf4j log4j java web
最近对系统中的旧项目实现log升级,选择了log4j2来代替log4j,作为最新一代的log实现,log4j2好在那里可以直接看log4j2性能章节。
这里写写如何从log4j升级到log4j2。
1. maven依赖的变化,对log4j的依赖变成了对log4j2的依赖,在实际使用过程中发现过旧的jboss logging会有问题,使用了3.3.0.Final支持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>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<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.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss-logging.version}</version>
</dependency>
<dependency>
<?xml version="1.0" encoding="UTF-8"?>
<configuration monitorInterval="60">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
</Console>
<RollingFile name="RollingFile" fileName="logs/sample.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz" immediateFlush="false" append="true">
<PatternLayout pattern="%d{yyyy.MM.dd ‘at‘ HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
<SizeBasedTriggeringPolicy size="50 MB" />
<DefaultRolloverStrategy max="10" />
</RollingFile>
<Async name="Async" includeLocation="true">
<AppenderRef ref="RollingFile" />
</Async>
</appenders>
<loggers>
<logger name="com.cloud.demo" additivity="false" level="trace">
<AppenderRef ref="Async" level="trace"/>
</logger>
<logger name="com.cloud.demo.service.impl.NewsServiceImpl" additivity="false" level="warn">
<AppenderRef ref="Async" level="warn"/>
</logger>
<logger name="org.springframework" additivity="false" level="warn">
<AppenderRef ref="Async" level="warn"/>
</logger>
<root level="info">
<AppenderRef ref="Async"/>
</root>
</loggers>
</configuration>
版权声明:本文为博主原创文章,未经博主允许不得转载。
log4j+slf4j迁移到log4j2+slf4j (Servlet3.0)
标签:log4j2 slf4j log4j java web
原文地址:http://blog.csdn.net/cloud_ll/article/details/47134259