SpringBoot默认整合了logback-classic⽇志框架,我们需要对logback⽇志框架进⾏配置 以⾃定义⽇志输出格式、⽇志⽂件配置、⽇志⽂件保存策略等信息
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <springProfile name="dev"> <pattern>%d{yyyy-MM-dd-HH:mm:ss E} %level [%thread]-%class[%line]: %msg%n</pattern> </springProfile> <springProfile name="!dev"> <pattern>%d{yyyy-MM-dd-HH:mm:ss E} %level [%thread]-%class[%line]: %msg%n</pattern> </springProfile> <!--⽇志的编码格式--> <charset>UTF-8</charset> </encoder> </appender> <!--这个就表示的是要把 ⽇志输出到⽂件(FileAppender)--> <appender name="file" class="ch.qos.logback.core.FileAppender"> <file>D:/log/output.log</file> <!--设置⽇志是否追加--> <append>true</append> <encoder> <pattern>%d{yyyy-MM-dd-HH:mm:ss.SSS} %level [%thread]-%class:%line>>%msg%n</pattern> <charset>UTF-8</charset> </encoder> <!--设置⽇志写⼊是否线程安全--> <prudent>false</prudent> </appender> <appender name="timeFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!--TimeBasedRollingPolicy 基于时间的滚动策略--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>d:/log/log-%d{yyyy-MM-ddHH}.log</fileNamePattern> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd-HH:mm:ss.SSS} %level [%thread]-%class:%line>>%msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <appender name="fixedFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>d:/log/fixedFile.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <fileNamePattern>log/fixedFile%i.log</fileNamePattern> <minIndex>1</minIndex> <maxIndex>10</maxIndex> </rollingPolicy> <!--SizeBasedTriggeringPolicy--> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <maxFileSize>5MB</maxFileSize> </triggeringPolicy> <encoder> <pattern>%d{yyyy-MM-dd-HH:mm:ss.SSS} %level [%thread]-%class:%line>>%msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <root level="info"> <appender-ref ref="stdout" /> <appender-ref ref="timeFile"/> </root> </configuration>
SpringBoot默认整合了logback-classic⽇志框架,我们需要对logback⽇志框架进⾏配置 以⾃定义⽇志输出格式、⽇志⽂件配置、⽇志⽂件保存策略等信息