SpringBoot--logger日志配置,使用@Slf4j注解

1、添加依赖:log4j的依赖在springboot下已经提供了

<!--定时任务和@Slf4j注解日志的依赖-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>


2、在需要生成日志的类上添加@Slf4j,即可直接使用log生成日志,更为方便

package com.example.demo.Log;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
* @author 王慧
* @description 日志
* @date 2020/1/8
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class SpringbootLoggerApplicationTests {

@Test
public void contextLoads() {
}

@Test
public void logger() {
log.info("=====>>>>> logger()");
}
}

3、下载安装lombok的插件

Ctrl+Alt+S打开Settings

猜你喜欢

转载自www.cnblogs.com/wangdahui/p/12168476.html