springboot built using environmentally @ Slf4j annotation of, for log management

If you do not want to write every private final Logger logger = LoggerFactory.getLogger (XXX.class); you can use an annotation @ Slf4j

We need to introduce to rely on:

<dependency>
   <groupId>org.projectlombok</groupId>
   <artifactId>lombok</artifactId>
</dependency>

Case code:

@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");
    }

}

 

 Because the default output info is on, it will not debug and trace output

 

 Third, pay attention: If you can not find the notes @ Slf4j injection variable log, then give IDE plug-ins installed lombok

If not, you can go to Baidu to install a plug-in lombok

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/11613639.html