(1) 首先去掉所有log4j相关的依赖,主要有:
1 2 3 4
|
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency>
|
1 2 3 4
|
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency>
|
(2) 为项目添加以下依赖:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-access</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </dependency>
|
(3) 删除项目/src/main/resources目录下的log4j.properties,并在该目录添加logback.xml文件,logback.xml文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <Target>System.out</Target> <encoder> <pattern>%date [%level] [%thread] %logger{80} [%file : %line] %msg%n</pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <encoder> <pattern>%date [%level] [%thread] %logger{80} [%file : %line] %msg%n</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${catalina.home}/logs/yzf/sql%d{yyyy-MM-dd}.log</fileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> </appender> <logger name="org.springframework" level="INFO" /> <logger name="org.apache" level="INFO" />
<logger name="com.itmuch" level="WARN" /> <root level="INFO"> <appender-ref ref="CONSOLE" /> <appender-ref ref="FILE" /> </root> </configuration>
|
http://www.tuicool.com/articles/INveIf
。
(2) slf4j-api、slf4j-log4j12以及log4j之间的关系
http://blog.csdn.net/tengdazhang770960436/article/details/18006127
(3) 参考文档:
http://blog.csdn.net/chenminghe271/article/details/38682493
相关文章