提交 77ca7d4a 编写于 作者: hebao@lab.ibiz5.com's avatar hebao@lab.ibiz5.com

日志输入配置调整,按照日志级别拆分文件,默认保留120天日志记录

上级 85983a78
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false"> <configuration debug="true">
<!-- 当前日志目录 -->
<property name="LOG_PATH" value="logs" /> <property name="LOG_PATH" value="logs" />
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %-40.40logger{39} : %msg%n" /> <!-- 归档日志目录 -->
<property name="LOG_ARCHIVED_PATH" value="logs/archived" />
<property name="LOG_MAXHISTORY" value="120" />
<!-- 控制台日志格式 -->
<!-- 彩色日志 --> <!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 --> <!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 彩色日志格式 --> <!-- 彩色日志格式 -->
<property name="LOG_PATTERN2" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr([${LOG_LEVEL_PATTERN:-%5p}]) %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" /> <property name="LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr([${LOG_LEVEL_PATTERN:-%5p}]) %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
<!-- 文件日志格式 -->
<property name="LOG_PATTERN2" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
<!-- 控制台输出 --> <!-- 控制台输出 -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
...@@ -16,25 +25,158 @@ ...@@ -16,25 +25,158 @@
<pattern>${LOG_PATTERN}</pattern> <pattern>${LOG_PATTERN}</pattern>
</encoder> </encoder>
</appender> </appender>
<!-- 按照每天生成日志文件 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- info 日志记录器,日期滚动记录 -->
<appender name="fileinfo" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 当前记录的日志文件的路径及文件名 -->
<file>${LOG_PATH}/log-info.log</file>
<!-- 日志记录器的滚动策略,按日期,按大小记录:这里是每天产生一个文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 归档的日志文件的路径,例如今天是2013-12-21日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。
而2013-12-21的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 -->
<!--设置日志命名模式-->
<fileNamePattern>${LOG_ARCHIVED_PATH}/log-info-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<!-- 除按日志记录之外,还配置了日志文件不能超过3M,若超过3M,日志文件会以索引0开始, 命名日志文件,例如log-error-2013-12-21.0.log -->
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--最多保留30天log-->
<maxHistory>${LOG_MAXHISTORY}</maxHistory>
</rollingPolicy>
<!-- 追加方式记录日志 -->
<append>true</append>
<!-- 日志文件的格式 -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN2}</pattern>
<charset>utf-8</charset>
</encoder>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- warn 日志记录器,日期滚动记录 -->
<appender name="filewarn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/log-warn.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名--> <fileNamePattern>${LOG_ARCHIVED_PATH}/log-warn-%d{yyyy-MM-dd}.%i.log
<FileNamePattern>${LOG_PATH}/ibzdst.%d{yyyy-MM-dd}.%i.log</FileNamePattern> </fileNamePattern>
<!--日志文件最大的大小-->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize> <maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy> </timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数--> <maxHistory>${LOG_MAXHISTORY}</maxHistory>
<MaxHistory>30</MaxHistory>
</rollingPolicy> </rollingPolicy>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern> <pattern>${LOG_PATTERN2}</pattern>
<charset>utf-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- error 日志记录器,日期滚动记录 -->
<appender name="fileerror" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/log-error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVED_PATH}/log-error-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>${LOG_MAXHISTORY}</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN2}</pattern>
<charset>utf-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>error</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- debug日志记录器,日期滚动记录 -->
<appender name="filedebug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/log-debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVED_PATH}/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--最多保留30天log-->
<maxHistory>${LOG_MAXHISTORY}</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN2}</pattern>
<charset>utf-8</charset>
</encoder> </encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>debug</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender> </appender>
<!-- trace日志记录器,日期滚动记录 -->
<appender name="filetrace" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/log-trace.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVED_PATH}/log-trace-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--最多保留30天log-->
<maxHistory>${LOG_MAXHISTORY}</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN2}</pattern>
<charset>utf-8</charset>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>trace</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- LOGSTASH -->
<!-- <appender name="LOGSTASH"
class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>172.16.102.211:9601</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"appname":"dstweb"}</customFields>
</encoder>
</appender> -->
<!-- SQL日志 -->
<logger name="com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor" level="DEBUG" />
<logger name="cn.ibizlab.core.extensions.util.DefaultMQProducerService" level="TRACE" />
<!-- 日志输出级别 --> <!-- 日志输出级别 -->
<root level="INFO"> <root level="INFO">
<appender-ref ref="Console" /> <appender-ref ref="Console" />
<appender-ref ref="file" /> <appender-ref ref="fileerror" />
<appender-ref ref="filewarn" />
<appender-ref ref="fileinfo" />
<appender-ref ref="filedebug" />
<appender-ref ref="filetrace" />
<!-- <appender-ref ref="LOGSTASH" /> -->
</root> </root>
</configuration> </configuration>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册