Logs are used to run some of the information recording system
Use JDBC database driver, write a unified interface layer, spring boot using SLF4 combined operation of logback.
Add the following dependencies in pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
In the development process, the call log recording method, call log process abstraction layer inside. springboot is already automatically help us configure the default log.
First, write a logger logger in the test program
Logger logger = LoggerFactory.getLogger(getClass());
Then write recording method in contextLoads () method:
//以下是日志的级别,由低到高排序
logger.trace("这是跟踪日志...");
logger.debug("这是调试日志...");
//springboot默认使用的是Info级别的
logger.info("这是Info日志...");
logger.warn("这是警告日志...");
logger.error("这是错误日志...");
Click Run discovery will only print the following three logs:
springboot default is Info level, if the children need to specify advanced level, you can add application.yml or properties file:
logging:
level:
com:
example: trace #example是我之前创建的项目GroupId
application.properties :, then run the test again, you can find:
Specify the log output file name:
Or add (properties): logging.level.com.example = trace, and then run the test program, produced a log file