springboot @Slf4j 配置日志

1.pom.xml 配置

 <dependency>
   <groupId>org.projectlombokgroupId>
   <artifactId>lombokartifactId>
   <version>${lombok.version}version>
   <optional>trueoptional>
 dependency>
 <parent>        	   
    <groupId>org.springframework.bootgroupId>            
    <artifactId>spring-boot-starter-parentartifactId> 
    <version>2.1.8.RELEASEversion>
 parent>

2.logback.xml 配置


<configuration>
	<include resource="org/springframework/boot/logging/logback/base.xml" />
	<logger name="org.springframework.web" level="INFO" />
	<appender name="dailyRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<File>./目录-logs/项目前缀.logFile>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			
			<FileNamePattern>./目录-logs/项目前缀.%d{yyyy-MM-dd}.logFileNamePattern>
			
			<maxHistory>7maxHistory>
		rollingPolicy>
		<encoder>
			<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level [%thread] %logger{50} - %msg%nPattern>
			<charset>UTF-8charset>
		encoder>
	appender>
	<root level="INFO">
		<appender-ref ref="dailyRollingFileAppender" />
	root>
	<jmxConfigurator/>
configuration>

3.日志注解配置

@Slf4j

log.info("xxxxxxxxxxxxxxx");

你可能感兴趣的:(Java项目,spring,boot,java,后端)