In SpringBoot, Logback is used to output logs by default. You can use the Logback configuration file logback. XML or the SpringBoot framework configuration file application.yml to output logs.

Through logback.xml configuration

<?xml version="1.0" encoding="UTF-8"? >
<configuration debug="false">
	<! Do not use relative path in LogBack configuration -->
	<property name="LOG_HOME" value="/test/log" />
	<! -- Console output -->
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<! Format output: %d indicates the date, %thread indicates the thread name, %-5level indicates the level of 5 characters from the left. % MSG indicates the log message, %n indicates the newline character.
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
		</encoder>
	</appender>
	<! Generate log files per day -->
	<appender name="FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<! -- Log file output file name -->
			<FileNamePattern>${LOG_HOME}/my.log.%d{yyyy-MM-dd}.log</FileNamePattern>
			<! -- Log file retention days -->
			<MaxHistory>30</MaxHistory>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<! Format output: %d indicates the date, %thread indicates the thread name, %-5level indicates the level of 5 characters from the left. % MSG indicates the log message, %n indicates the newline character.
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
		</encoder>
		<! -- Maximum size of log file -->
		<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
			<MaxFileSize>10MB</MaxFileSize>
		</triggeringPolicy>
	</appender>

	<! -- Log output level -->
	<root level="INFO">
		<appender-ref ref="STDOUT" />
		<appender-ref ref="FILE" />
	</root>
</configuration>
Copy the code

Configuration via application.yml

${LOG_HOME}/my.log.%d{YYYY-MM-dd}.log. ${LOG_HOME}/my.log.

logging:
  pattern:
    file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
    console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
  path: "./logs/"
  file: "./logs/my.log"
  file.max-size: 10MB
  level:
    root: INFO
Copy the code

reference

SpringBoot Logback log configuration