<!--
configuration 节点属性说明:
scan: 开启自动扫描,扫描配置文件是否发生变化,变化后自动更新配置,默认1分钟扫描一次
scanPeriod: 配置扫描频次,单位可以为:milliseconds(毫秒), seconds(秒), minutes (分),hours(时)
-->
<configuration debug="true" scan="true" scanPeriod="30 seconds">
<!--引入spring boot 默认的logback配置-->
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<!--引入spring boot logback控制台日志配置-->
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<!--配置日志文件输出路径-->
<property name="LOG_PATH" value="/data/logs/project/"/>
<!--配置项目名称,为拼接日志文件名-->
<property name="PROJECT_NAME" value="project"/>
<!--配置时间格式化格式-->
<timestamp key="DATE_TIME" datePattern="yyyy-MM-dd HH:mm:ss:S"/>
<!--配置日期格式化格式-->
<timestamp key="DATE" datePattern="yyyy-MM-dd"/>
<!-- DEBUG级别日志文件配置-->
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--配置过滤器,只输出DEBUG级别日志-->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!--日志输出格式,此处引用spring boot 默认logback配置格式-->
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<!--日志文件输出配置-->
<file>${LOG_PATH}${PROJECT_NAME}-DEBUG.log</file>
<!--以下为日志文件归档配置-->
<!--配置归档文件名及索引范围-->
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${LOG_PATH}${PROJECT_NAME}-DEBUG-${DATE}-%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<!--配置归档大小,当日志文件超过10MB时触发归档-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>10MB</maxFileSize>
</triggeringPolicy>
</appender>
<!-- INFO级别日志文件-->
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_PATH}${PROJECT_NAME}-INFO.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${LOG_PATH}${PROJECT_NAME}-INFO-${DATE}-%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>10MB</maxFileSize>
</triggeringPolicy>
</appender>
<!-- WARN级别日志文件-->
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_PATH}${PROJECT_NAME}-WARN.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${LOG_PATH}${PROJECT_NAME}-WARN-${DATE}-%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>10MB</maxFileSize>
</triggeringPolicy>
</appender>
<!-- ERROR级别日志文件-->
<appender name="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>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_PATH}${PROJECT_NAME}-ERROR.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${LOG_PATH}${PROJECT_NAME}-ERROR-${DATE}-%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>10MB</maxFileSize>
</triggeringPolicy>
</appender>
<!--
logback 日志监听配置:
level: 配置日志监听级别,当前配置为DEBUG
-->
<root level="DEBUG">
<!--控制台日志输出,引用的是console-appender.xml中定义的CONSOLE appender-->
<appender-ref ref="CONSOLE" />
<!--以下为各日志级别文件输出,为上边定义的各日志级别的appender-->
<appender-ref ref="DEBUG"/>
<appender-ref ref="INFO"/>
<appender-ref ref="WARN"/>
<appender-ref ref="ERROR"/>
</root>
</configuration>