http://412887952-qq-com.iteye.com/blog/2306441
http://www.cnblogs.com/mailingfeng/p/3499436.html-
logback的日志文件命名是logback-spring.xml,而不是logback.xml,因为命名为logback-spring.xml的日志配置文件,spring boot可以为它添加一些spring boot特有的配置项。
http://blog.csdn.net/yingxiake/article/details/51276671
logback-spring.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- <include resource="org/springframework/boot/logging/logback/base.xml" /> -->
<!-- <logger name="org.springframework.web" level="INFO"/> -->
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder><!-- 格式化输出 -->
<pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS}] %level - %m%n</pattern>
</encoder>
</appender>
<!-- 控制台输出级别 -->
<root level="info">
<appender-ref ref="console" />
</root>
<!-- 文件输出 -->
<appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${LOG_FILE}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd,aux}/${LOG_FILE}-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>20MB</maxFileSize>
<maxHistory>180</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder><!-- 必须指定,否则不会往文件输出内容 -->
<pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS}] %level ${LOG_FILE}[%X{action}-%X{taskId}] %logger : %message%n</pattern>
</encoder>
</appender>
<!-- 文件输出_error -->
<appender name="fileErrorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${LOG_FILE}-error.log</file>
<!-- 过滤掉ERROR级别以下的日志不输出到文件中 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd,aux}/${LOG_FILE}-error-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>20MB</maxFileSize>
<maxHistory>180</maxHistory>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS}] %level ${LOG_FILE} %logger : %message%n</pattern>
</encoder>
</appender>
<!-- 文件输出级别 -->
<root level="info">
<appender-ref ref="fileAppender" />
<appender-ref ref="fileErrorAppender" />
</root>
</configuration>
application.properties
logging.path=./logs
logging.file=spring_tutorial
日志参数化
1.日志配置文件中添加占位符
<encoder><!-- 必须指定,否则不会往文件输出内容 -->
<pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS}] %level ${LOG_FILE}[%X{action}-%X{taskId}] %logger : %message%n</pattern>
</encoder>
2.写入日志
import org.slf4j.MDC;
MDC.put("action", "query");
MDC.put("taskId", "1111");
logger.info("info信息");
3.效果