1 <configuration> 2 <!--日志入库的配置,这里通过springProperty标签直接读取application.application中日志的配置--> 3 <springProperty scope="context" name="logging.level.root" source="logging.level.root"/> 4 <springProperty scope="context" name="logging.file.path" source="logging.file.path" defaultValue="log"/> 5 <!-- 输出到控制台 --> 6 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 7 <encoder> 8 <!-- 输出格式 --> 9 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{36} - %msg%n</pattern> 10 </encoder> 11 </appender> 12 13 <!-- error级别单独记录 --> 14 <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> 15 <file>${logging.file.path}/error.log</file> 16 <!-- 以day为单位自动回滚 --> 17 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 18 <fileNamePattern>${logging.file.path}/error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> 19 <!--最多保留7天--> 20 <maxHistory>7</maxHistory> 21 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 22 <!-- or whenever the file size reaches 10MB --> 23 <maxFileSize>10MB</maxFileSize> 24 </timeBasedFileNamingAndTriggeringPolicy> 25 </rollingPolicy> 26 <encoder> 27 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n</pattern> 28 </encoder> 29 <!-- error级别过滤器 --> 30 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 31 <level>ERROR</level> 32 <onMatch>ACCEPT</onMatch> 33 <onMismatch>DENY</onMismatch> 34 </filter> 35 </appender> 36 37 <!-- warn级别单独记录 --> 38 <appender name="warnAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> 39 <file>${logging.file.path}/warn.log</file> 40 <!-- 以day为单位自动回滚 --> 41 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 42 <fileNamePattern>${logging.file.path}/warn-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> 43 <!-- 最多记录7天日志 --> 44 <maxHistory>7</maxHistory> 45 <timeBasedFileNamingAndTriggeringPolicy 46 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 47 <!-- 文件大小到达10MB自动打包 --> 48 <maxFileSize>10MB</maxFileSize> 49 </timeBasedFileNamingAndTriggeringPolicy> 50 </rollingPolicy> 51 <encoder> 52 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n</pattern> 53 </encoder> 54 <!-- warn级别过滤器 --> 55 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 56 <level>WARN</level> 57 <onMatch>ACCEPT</onMatch> 58 <onMismatch>DENY</onMismatch> 59 </filter> 60 </appender> 61 62 <appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> 63 <file>${logging.file.path}/info.log</file> 64 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 65 <fileNamePattern>${logging.file.path}/info-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> 66 <maxHistory>7</maxHistory> 67 <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 68 <!-- or whenever the file size reaches 100MB --> 69 <maxFileSize>10MB</maxFileSize> 70 </timeBasedFileNamingAndTriggeringPolicy> 71 </rollingPolicy> 72 <encoder> 73 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n</pattern> 74 </encoder> 75 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 76 <level>INFO</level> 77 <onMatch>ACCEPT</onMatch> 78 <onMismatch>DENY</onMismatch> 79 </filter> 80 </appender> 81 82 <!-- 根,所有logger的祖先 --> 83 <root level="${logging.level.root}"> 84 <appender-ref ref="STDOUT"/> 85 <appender-ref ref="errorAppender"/> 86 <appender-ref ref="warnAppender"/> 87 <appender-ref ref="infoAppender"/> 88 </root> 89 </configuration>
<configuration>
<!--日志入库的配置,这里通过springProperty标签直接读取application.application中日志的配置-->
<springProperty scope="context" name="logging.level.root" source="logging.level.root"/>
<springProperty scope="context" name="logging.file.path" source="logging.file.path" defaultValue="log"/>
<!-- 输出到控制台 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- 输出格式 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- error级别单独记录 -->
<appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.file.path}/error.log</file>
<!-- 以day为单位自动回滚 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logging.file.path}/error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!--最多保留7天-->
<maxHistory>7</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 10MB -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
<!-- error级别过滤器 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- warn级别单独记录 -->
<appender name="warnAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.file.path}/warn.log</file>
<!-- 以day为单位自动回滚 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logging.file.path}/warn-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- 最多记录7天日志 -->
<maxHistory>7</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- 文件大小到达10MB自动打包 -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
<!-- warn级别过滤器 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.file.path}/info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logging.file.path}/info-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxHistory>7</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 根,所有logger的祖先 -->
<root level="${logging.level.root}">
<appender-ref ref="STDOUT"/>
<appender-ref ref="errorAppender"/>
<appender-ref ref="warnAppender"/>
<appender-ref ref="infoAppender"/>
</root>
</configuration>