Use slf4j

Log abstraction layer The logging implementation
slf4j Logbck, log4J, Commons-logging, java.util.logging
  • The bottom layer of SpringBoot uses slF4J + Logback to log
  • Log level: trace< DEBUG
  • The higher the log level is, the less information is displayed

Custom log format

  • Yml format
logging.level.root=info # specify the global log level
logging.level.cn.ccb.dao=debug # specify a packet log level
Copy the code
  • XML format, just put the corresponding XML file under Resources, the specific XML file name is as follows:
Logging System Customization
Logback logback-spring.xml.logback-spring.groovy.logback.xml or logback.groovy
Log4j2 log4j2-spring.xml or log4j2.xml
Java Util Logging logging.properties

Note: both logback and logback-spring. XML can be used to configure logback, but the loading order is not the same: logback.xml– >application

SpringBoot processing of the logging framework

SpringBoot automatically ADAPTS to all logging frameworks. If you want to unify logging, you only need to remove logging dependencies of imported frameworks, such as Commons-logging used by the Spring framework

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
Copy the code