Spring Boot实践(二):logback日志配置
2021-02-15 04:19
标签:配置 lse period ogg text res deny utf-8 http 1、logback是什么? 工作中一直用的是log4j日志框架,接触了SpringBoot后,因为logback是默认框架,才开始进行了解。 来看下官网的相关介绍。 可以看到,logback是log4j的进化版,是为了替代log4j的。 logback分三个模块: 2、为什么要用logback? logback既然作为Spring Boot的默认框架,是有很多优点的,官网上也有优点说明,这里我截出一部分, 可以看到,优点非常多,内存小、运行速度快、测试充分、相关文档充分、支持XML和Groovy配置、自动加载配置、I/O故障自动恢复、自动删除历史归档日志等等,后面还有很多。 既然这么好,那肯定要用了。 3、logback的使用 各节点属性与log4j的类似,下面配置有比较详细的说明,官网也有相关资料。 由于是配合SpringBoot使用的,我命名的是logback-spring.xml,有SpringBoot解析,下面贴一下我的配置: 至此,debug、info、warn、error等相关日志配置大功告成了! Spring Boot实践(二):logback日志配置 标签:配置 lse period ogg text res deny utf-8 http 原文地址:https://www.cnblogs.com/rimmy/p/12716900.html
xml version="1.0" encoding="UTF-8"?>
configuration debug="false" scan="true" scanPeriod="60 seconds">
springProperty scope="context" name="log.path" source="path.log"/>
appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
encoder>
pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) --- [%thread] %cyan(%logger) : %msg%npattern>
charset>UTF-8charset>
encoder>
appender>
appender name="debug_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
File>${log.path}/debug/debug.logFile>
append>trueappend>
filter class="ch.qos.logback.classic.filter.ThresholdFilter">
level>DEBUGlevel>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
fileNamePattern>${log.path}/debug/debug.%d.%i.logfileNamePattern>
maxHistory>30maxHistory>
totalSizeCap>500MBtotalSizeCap>
maxFileSize>4MBmaxFileSize>
rollingPolicy>
encoder>
pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level --- [%thread] %logger : %msg%npattern>
charset>UTF-8charset>
encoder>
appender>
appender name="info_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
File>${log.path}/info.logFile>
append>trueappend>
filter class="ch.qos.logback.classic.filter.ThresholdFilter">
level>INFOlevel>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
fileNamePattern>${log.path}/info.%d.%i.logfileNamePattern>
maxHistory>30maxHistory>
totalSizeCap>400MBtotalSizeCap>
maxFileSize>2MBmaxFileSize>
rollingPolicy>
encoder>
pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level --- [%thread] %logger : %msg%npattern>
charset>UTF-8charset>
encoder>
appender>
appender name="warn_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
File>${log.path}/warn/warn.logFile>
append>trueappend>
filter class="ch.qos.logback.classic.filter.ThresholdFilter">
level>WARNlevel>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
fileNamePattern>${log.path}/warn/warn.%d.%i.logfileNamePattern>
maxHistory>30maxHistory>
totalSizeCap>100MBtotalSizeCap>
maxFileSize>2MBmaxFileSize>
rollingPolicy>
encoder>
pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level --- [%thread] %logger : %msg%npattern>
charset>UTF-8charset>
encoder>
appender>
appender name="error_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
File>${log.path}/error/error.logFile>
append>trueappend>
filter class="ch.qos.logback.classic.filter.LevelFilter">
level>ERRORlevel>
onMatch>ACCEPTonMatch>
onMismatch>DENYonMismatch>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
fileNamePattern>${log.path}/error/error.%d.%i.logfileNamePattern>
maxHistory>60maxHistory>
totalSizeCap>50MBtotalSizeCap>
maxFileSize>2MBmaxFileSize>
rollingPolicy>
encoder>
pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level --- [%thread] %logger : %msg%npattern>
charset>UTF-8charset>
encoder>
appender>
root level="INFO">
appender-ref ref="STDOUT" />
appender-ref ref="debug_log" />
appender-ref ref="info_log" />
appender-ref ref="warn_log" />
root>
configuration>
文章标题:Spring Boot实践(二):logback日志配置
文章链接:http://soscw.com/index.php/essay/55492.html