SpringBoot (10)--log framework and SLF4j use

Main content:
(1) Log framework
(2) Use of SLF4j


1 Log Framework

Logging frameworks on the market;
JUL, JCL, Jboss-logging, logback, log4j, log4j2, slf4j….

日志门面 (日志的抽象层) 
JCL(Jakarta Commons Logging) SLF4j(Simple Logging
Facade for Java) jboss-logging

日志实现
Log4j JUL(java.util.logging
Log4j2 Logback

Best combination
Log facade: SLF4J;
log implementation: Logback;

SpringBoot:
The bottom layer is the Spring framework, and the Spring framework uses JCL by default; '
SpringBoot uses SLF4j and logback;


2. Using SLF4j

1. How to use SLF4j in the system

The official website of SLF4j uses

In the future development, the invocation of the logging method should not directly call the implementation class of the log, but call the method in the log abstraction layer;
import the jar of slf4j and the implementation jar of logback into the system

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HelloWorld {
  public static void main(String[] args) {
    Logger logger = LoggerFactory.getLogger(HelloWorld.class);
    logger.info("Hello World");
  }
}

Icon:

write picture description here

Each log implementation framework has its own configuration file. After using slf4j, the configuration file is still made into the configuration file of the log implementation framework itself ;

2. Legacy issues

a (slf4j+logback): Spring (commons-logging), Hibernate (jboss-logging), MyBatis, xxxx
unified logging, even if other frameworks use slf4j for output together with me?

write picture description here

How to unify all logs in
the system to slf4j; 1. Exclude other logging frameworks in the system first;
2. Replace the original logging framework with intermediate packages;
3. We import other implementations of slf4j

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325588753&siteId=291194637