logback 集成需要jar包如下
<!-- logback and slf4j -->
<dependency>
<groupId>ch.qos.logback</groupId >
<artifactId>logback-core</artifactId >
<version>1.1.2</version >
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId >
<artifactId>logback-classic</artifactId >
<version>1.1.2</version >
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version >
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId >
<version>1.7.10</version >
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version >
</dependency>
====以下为配置====
<?xml version="1.0" encoding="UTF-8"?>
<configuration> <!-- MaxHistory:日志保存的天数 --> <property name="logBase" value="${HOME:-./logs}" /> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{yy/MM/dd HH:mm:ss.SSS} %-5level %line %logger{15} - %msg %n</pattern> <charset>UTF-8</charset> </encoder> </appender> <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${logBase}/logs.%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>1</MaxHistory> </rollingPolicy> <encoder> <pattern>%d{yy/MM/dd HH:mm:ss.SSS} %-5level %line %logger{15} - %msg %n</pattern> <charset>UTF-8</charset> </encoder> </appender> <appender name="file—error" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY </onMismatch> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${logBase}/error.%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>1</MaxHistory> </rollingPolicy> <encoder> <pattern>%d{yy/MM/dd HH:mm:ss.SSS} %-5level %line %logger{15} - %msg %n</pattern> <charset>UTF-8</charset> </encoder> </appender> <logger name="cn.springmvc" level="TRACE" /> <logger name="net.spy.memcached" level="DEBUG" /> <logger name="java.sql.Connection" level="INFO" /> <logger name="java.sql.Statement" level="INFO" /> <logger name="org.springframework" level="INFO" /> <logger name="org.hibernate" level="INFO" /> <logger name="org.apache" level="INFO" /> <logger name="org.quartz" level="INFO" /> <logger name="com.google.code.yanf4j" level="WARN" /> <logger name="net.rubyeye.xmemcached" level="WARN" /> <!-- 日志级别:TRACE < DEBUG < INFO < WARN < ERROR --> <root level="INFO"> <!-- 输出到控制台 --> <appender-ref ref="stdout" /> <!-- 当前级别可输出的日志全部写入一个文件 --> <appender-ref ref="file" /> <!-- error级别日志单独写入一个文件 --> <appender-ref ref="file—error" /> </root></configuration>