参考:https://blog.csdn.net/qq_26344609/article/details/78905845
如果不想每次都写private final Logger logger = LoggerFactory.getLogger(XXX.class); 可以用注解@Slf4j
一、在pom文件加入依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
package com.sell; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; /** * 日志测试 */ @RunWith(SpringRunner.class) @SpringBootTest @Slf4j public class LoggerTest { private final Logger logger = LoggerFactory.getLogger(LoggerTest.class); /** * 一、传统方式实现日志 */ @Test public void test1(){ logger.debug("debug message"); logger.warn("warn message"); logger.info("info message"); logger.error("error message"); logger.trace("trace message"); } /** * 二、注解方式实现日志 */ @Test public void test2(){ log.debug("debug message"); log.warn("warn message"); log.info("info message"); log.error("error message"); log.trace("trace message"); } } --------------------- 作者:好运哥888 来源:CSDN 原文:https://blog.csdn.net/qq_26344609/article/details/78905845 版权声明:本文为博主原创文章,转载请附上博文链接!