pom依赖:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>kashop-server</contextName>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<encoder>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.files}</file>
<!-- 日志输出编码 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志输出文件名 -->
<fileNamePattern>${logging.files}.%d{yyyy-MM-dd}</fileNamePattern>
<!-- 日志保存的最大时间 -->
<maxHistory>10</maxHistory>
</rollingPolicy>
<encoder>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 在程序的开发测试阶段,可以调整level的级别,常用级别优先级为: -->
<!-- TRACE < DEBUG < INFO < WARN < ERROR -->
<logger name="cn.ce.ebiz" />
<logger name="com.alibaba.dubbo" level="INFO"/>
<logger name="org.apache.zookeeper.proto" level="INFO"/>
<!--log4jdbc -->
<logger name="jdbc.sqltiming" />
<logger name="jdbc.resultset" />
<!--打印SQL-->
<logger name="java.sql.Connection" level="DEBUG" />
<logger name="java.sql.Statement" level="DEBUG" />
<logger name="java.sql.PreparedStatement" level="DEBUG" />
<root level="DEBUG">
<appender-ref ref="console" />
<appender-ref ref="rollingFile" />
</root>
</configuration>
参考地址:http://www.cnblogs.com/beiyeren/p/4196134.html