1. Spring Boot uses Logback by default
By default, Spring Boot logs using SLF4J + Logback and outputs to the console at the INFO level. You should already see many info-level logs when running the application and other examples.
2, rely on
We don’t need to add this dependency directly in actual development. Spring-boot-starter includes spring-boot-starter-logging, which is the default logging framework for Spring Boot.
3, use,
(1) Direct use
import org.slf4j.LoggerFactory; public class HttpUtil { private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class); void testLog(){ log.info("hello world."); }}Copy the code
(2) Use logs with Lombok
Private static final Logger Logger = loggerFactory.getLogger (httputil.class); .
import lombok.extern.log4j.Log4j2; @Log4j2 public class ApplicationMain { public static void main(String[] args) { log.info("hello world."); }}Copy the code
4. Configuration file location
Configuration file location
Organize the configuration file names as follows to load them correctly: logback-spring.xml
Log Level The log levels are as follows: TRACE < DEBUG < INFO < WARN < ERROR < FATAL. Can be used directly in code
The trace (" trace log "); The debug (" the debug log "); The info (log "info"); The log. The error (" error log ");Copy the code
It is used in combination with the log configuration file to control the level of log output
5, reference
My.oschina.net/u/3730149/b… Blog.csdn.net/Inke88/arti… www.jianshu.com/p/33135f341…