If you do not want to write every private final Logger logger = LoggerFactory.getLogger (XXX.class); you can use an annotation @ Slf4j
First, in the pom file to the dependence
org.projectlombok lombokSecond, the code
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;
/**
- Log test
* /
@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”);
}
}
Output is as follows:
Because the default output is above the info, debug seen in the figure below, the trace is not output
Third, pay attention: If you can not find the notes @ Slf4j injection variable log, then give IDE plug-ins installed lombok ,,
Below idea, for example
1, File → settings → Plugins, then click on the "Browse repositories" in Fig.
2, input lombok search plug-in, point install installation, reboot after installing idea
This time you can enter log prompted the