Create logback.xml log in the resources directory
The specific configuration content is as follows:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- The information output by %m, %p log level, %t thread name, %d date, %c class full name ,%i index [increment from the number 0],,, --> <!-- appender is a child node of configuration, and is a component responsible for writing logs. --> <!-- ConsoleAppender: output the log to the console --> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d %p% thread (%file:%line\)- %m%n</pattern> <!-- The console should also use UTF-8, don’t use GBK, otherwise Chinese characters will be garbled--> <charset>UTF-8</ pattern> charset> </encoder> </appender> <!-- RollingFileAppender: Rolling file, first record the log to the specified file, when a certain condition is met, record the log to other files --> <! <! <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>logs/debug/debug.log</File> <!-- rollingPolicy: When rolling occurs, decide RollingFileAppender The behavior involves file movement and renaming. --> <!-- TimeBasedRollingPolicy: The most commonly used rolling strategy, it develops a rolling strategy based on time, and is responsible for both rolling and starting rolling --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <!-- The name of the active file will be changed every once in a while according to the value of fileNamePattern --> <!-- File name: log/demo.2017-12-05.0.log --> <fileNamePattern>logs/ debug/debug-%d.%i.log</fileNamePattern> <!-- Each time a log file is generated, the storage period of the log file is 30 days --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <!-- maxFileSize: This is the size of the active file, the default value is 10MB, it can be changed to 1KB during testing to see the effect --> <maxFileSize> 10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <!-- pattern node, used to set the log input format--> <pattern> %d %p (%file:%line\)-% m%n </pattern> <!-- Log encoding: Set the character set here---> <charset>UTF-8</charset> </encoder> </appender> <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>logs/error/error.log</File> <!-- rollingPolicy: When rolling occurs, Determines the behavior of RollingFileAppender, involving file movement and renaming. --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- The name of the active file will be based on the value of fileNamePattern at regular intervals Change once --> <!-- File name: log/demo.2017-12-05.0.log --> <fileNamePattern>logs/error/error-%d.%i.log</fileNamePattern> <!-- Each time a log file is generated, the storage period of the log file is 30 days --> <maxHistory>30</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <!-- maxFileSize: This is the size of the active file. The default value is 10MB, and it can be changed to 1KB during testing to see the effect --> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <!-- pattern node, used to set the input format of the log --> <pattern> %d %p %thread (%file:%line\)- %m%n </pattern> <!-- The encoding of logging: Set the character set here---> <charset>UTF-8 </charset> </encoder> <!-- This log file only records ERROR level--> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> < onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- Console output log level --> <root level="info"> <appender-ref ref=" CONSOLE" /> </root>appender-ref ref="CONSOLE" /> <appender-ref ref="DEBUG_FILE" /> <appender-ref ref="ERROR_FILE" /> <!-- Specify the logging level of a package in the project when there is log operation behavior --> <!-- com.xinxin.edulive.mapper is the root package, that is, as long as it occurs under this root package The authority for all log operations is DEBUG --> <!-- The level is [from high to low]: FATAL> ERROR> WARN> INFO> DEBUG> TRACE --> <logger name="com.juejueguai.logback "level="DEBUG"> <appender-ref ref="DEBUG_FILE" /> </logger> </configuration>