<?xml version="1.0" encoding="UTF-8"?>
<!--
scan:
当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。(这个功能可以在不重启运行环境下,调整打印日志的细节,方便定位问题)
scanPeriod:
设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。
debug:
当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。
-->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!--
logger:日志所处的包
level:日志打印级别
-->
<!--<logger name="org.springframework" level="WARN" />-->
<contextName>logback</contextName>
<property name="log.path" value="./" />
<property name="project.name" value="springboot_logback" />
<property name="smtpHost" value="smtp.163.com" />
<!--<property name="smtpPort" value="25" />-->
<property name="username" value="xxx@163.com" />
<property name="password" value="xxx" />
<property name="SSL" value="false" />
<property name="email_to" value="xxx@qq.com" />
<property name="email_from" value="xxx@163.com" />
<property name="email_subject" value="【Error】: %logger" />
<!--输出到控制台-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}:%4p %t %F:%L - %m%n</pattern>
</encoder>
</appender>
<!--文件输出的格式设置 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/${project.name}.log</file>
<!-- 文件输出的日志 的格式 -->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}:%4p %t %F:%L - %m%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集,防止中文乱码 -->
</encoder>
<!-- 配置日志所生成的目录以及生成文件名的规则 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
<!--<fileNamePattern>%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>-->
<!-- 如果按天来回滚,则最大保存时间为365天,365天之前的都将被清理掉 -->
<maxHistory>365</maxHistory>
<!-- 日志总保存量为1GB -->
<totalSizeCap>1GB</totalSizeCap>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!--文件达到 最大30KB时会被压缩和切割 -->
<maxFileSize>30KB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<smtpHost>${smtpHost}</smtpHost>
<smtpPort>${smtpPort}</smtpPort>
<username>${username}</username>
<password>${password}</password>
<SSL>${SSL}</SSL>
<asynchronousSending>false</asynchronousSending>
<to>${email_to}</to>
<from>${email_from}</from>
<subject>${email_subject}</subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout" >
<pattern>%date%level%thread%logger{0}%line%message</pattern>
</layout>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
<expression>
if(level > WARN) {
return true;
}
return false;
</expression>
</evaluator>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<root level="debug">
<appender-ref ref="console" />
<appender-ref ref="file" />
<appender-ref ref="EMAIL"/>
</root>
</configuration>