当前位置: 代码迷 >> 综合 >> logback-spring模板
  详细解决方案

logback-spring模板

热度:65   发布时间:2023-09-14 09:00:55.0
<?xml version="1.0" encoding="UTF-8"?>
<configuration><property name="FILE_ERROR_PATTERN"value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} %file:%line: %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/><include resource="org/springframework/boot/logging/logback/defaults.xml"/><appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>ERROR</level></filter><encoder><pattern>${CONSOLE_LOG_PATTERN}</pattern><charset>UTF-8</charset></encoder></appender><appender name="FILE_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender"><filter class="ch.qos.logback.classic.filter.LevelFilter"><!--过滤 Error--><level>ERROR</level><!--匹配到就禁止--><onMatch>DENY</onMatch><!--没有匹配到就允许--><onMismatch>ACCEPT</onMismatch></filter><!--滚动策略,按照时间滚动 TimeBasedRollingPolicy--><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!--文件路径,定义了日志的切分方式——把每一天的日志归档到一个文件中,以防止日志填满整个磁盘空间--><FileNamePattern>../log4j-info/projectName/info.%d{yyyy-MM-dd}.part_%i.log</FileNamePattern><!--只保留最近10天的日志--><maxHistory>5</maxHistory><cleanHistoryOnStart>true</cleanHistoryOnStart><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><encoder><pattern>${FILE_LOG_PATTERN}</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder></appender><appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"><!--如果只是想要 Error 级别的日志,那么需要过滤一下,默认是 info 级别的,ThresholdFilter--><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>Error</level></filter><!--滚动策略,按照时间滚动 TimeBasedRollingPolicy--><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!--文件路径,定义了日志的切分方式——把每一天的日志归档到一个文件中,以防止日志填满整个磁盘空间--><FileNamePattern>../log4j-error/projectName/error.%d{yyyy-MM-dd}.part_%i.log</FileNamePattern><!--只保留最近10天的日志--><maxHistory>5</maxHistory><cleanHistoryOnStart>true</cleanHistoryOnStart><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><!-- maxFileSize:这是活动文件的大小,默认值是10MB,本篇设置为1KB,只是为了演示 --><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><encoder><pattern>${FILE_ERROR_PATTERN}</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder></appender><root level="info"><appender-ref ref="CONSOLE"/><appender-ref ref="FILE_INFO"/><appender-ref ref="FILE_ERROR"/></root>
</configuration>
  相关解决方案