很多第三方库使用log4j或common-logging作为日志组件,使用slf4j统一日志输出:
log4j-over-slf4j-1.x.x.jar 用于替代 log4j
jcl-over-slf4j-1.x.x.jar 用于替代 common-logging
[还有其他对应的jdk/android/...日志匹配库]
classpath中加入:
-
jcl-over-slf4j-1.x.x.jar
-
log4j-over-slf4j-1.x.x.jar
-
logback-classic-1.xx.jar
-
logback-core-1.xx.jar
-
slf4j-api-1.xx.jar
-
import org.slf4j.Logger;
-
import org.slf4j.LoggerFactory;
-
-
protected Logger log = LoggerFactory.getLogger(getClass());
logback-test.xml:
-
<configuration scan="false" debug="false">
-
-
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
-
<encoder>
-
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %C.%M %L - %msg%n</pattern>
-
</encoder>
-
</appender>
-
-
<logger name="com.crop" level="debug"/>
-
-
<root level="info">
-
<appender-ref ref="STDOUT" />
-
</root>
-
</configuration>
logback.xml
-
<configuration scan="false" debug="false">
-
<!--
-
<property file="app.properties" />
-
-->
-
-
<contextName>App</contextName>
-
-
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
-
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-
<fileNamePattern>logs/App.%d{yyyy-MM-dd}.log</fileNamePattern>
-
<maxHistory>180</maxHistory>
-
</rollingPolicy>
-
-
<encoder>
-
<pattern>%d [%thread] %-5level %C.%M %L - %msg%n</pattern>
-
</encoder>
-
</appender>
-
-
<logger name="com.crop" level="debug"/>
-
-
<root level="info">
-
<appender-ref ref="FILE"/>
-
</root>
-
</configuration>
阅读(4155) | 评论(0) | 转发(0) |