As a reminder, the configuration file when using Logback in Spring Boot is listed below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE logback>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<!--Use the default standard output-->
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<!--Change the output pattern of standard output from the default-->
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %t [%-5p] [%c] %m%n"/>
<!--I want to separate the file output by INFO and ERROR, so define them separately.-->
<!--Definition for INFO level output-->
<appender name="FILE_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
<file>Log file name</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>Log file name.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
</appender>
<!--Definition for ERROR level output-->
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--Define a filter to output only the ERROR level-->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<charset>UTF-8</charset>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
<file>Error log file name</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>Error log file name.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
</appender>
<!--Output INFO level or higher-->
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE_INFO" />
<appender-ref ref="FILE_ERROR" />
</root>
</configuration>
Recommended Posts