参考1:http://blog.csdn.net/linwei_1029/article/details/8844939
参考2:http://www.cnblogs.com/Sinte-Beuve/p/5758971.html
1. 首先准备相关jar包,如下:
slf4j-api-1.7.2.jar,logback-classic-1.0.9.jar,logback-core-1.0.9.jar
2. 在src 文件路径下,存放logback.xml文件,具体内容如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 控制台日志:输出全部日志到控制台 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<Encoding>UTF-8</Encoding>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
</pattern>
</encoder>
</appender>
<!-- 文件日志:输出全部日志到文件 -->
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<Encoding>UTF-8</Encoding>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>f:/logs/mts.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
3、maven依赖
<!-- logback 只配置这个,相关依赖jar会下载下来 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
参考2:http://www.cnblogs.com/Sinte-Beuve/p/5758971.html
1. 首先准备相关jar包,如下:
slf4j-api-1.7.2.jar,logback-classic-1.0.9.jar,logback-core-1.0.9.jar
2. 在src 文件路径下,存放logback.xml文件,具体内容如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 控制台日志:输出全部日志到控制台 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<Encoding>UTF-8</Encoding>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
</pattern>
</encoder>
</appender>
<!-- 文件日志:输出全部日志到文件 -->
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<Encoding>UTF-8</Encoding>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>f:/logs/mts.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
3、maven依赖
<!-- logback 只配置这个,相关依赖jar会下载下来 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>