There are actually two ways to do this.
The first is actually a way that was used a long time ago. You just need to add the following to the code:
private final Logger logger= LoggerFactory.getLogger(DemoApplicationTests.class)
This way is obviously more frivolous, if every class to add it is not very low.
A second
lombok solves this problem for us without having to write a single line of code for every class.
To use lombok, you need to add the following dependencies:
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
dependency>
Using
is also very simple. You just need to annotate the class with a comment @Slf4j as follows:
@Slf4j
class DemoApplicationTests {
@Test
public void test(){
log.debug("输出DEBUG日志.......");
}
}