java—Springboot and slf4j log operations

1. If you want to use automatic log printing, you first need to inject dependencies into the project <!–lombok–> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> 2. Modify configuration file information: # slf4j logging: level: springboot:trace config: classpath:logback-dev.xml 3. Create the logback-dev.xml file under resources <?xml version=”1.0″ encoding=”UTF-8″?> <!– The log levels from […]

java—Springboot and slf4j log operations

1. Dependency injection <!–lombok–> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> 2.Configuration file information: # slf4j logging: level: springboot:trace config: classpath:logback-dev.xml 3.Create the logback-dev.xml file under resources <?xml version=”1.0″ encoding=”UTF-8″?> <!– The log levels from low to high are TRACE < DEBUG < INFO < WARN < ERROR < FATAL. If set to […]

Use of log4j, log4j2, slf4j, logback

Usage of log4j, log4j2, slf4j, logback 1. Use log4j dependencies alone <!– log4j1: 1.2.17 –> <!– ============================================== ========== –> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!– ============================================== ========== –> 2. Using Log4j2 dependencies alone <!–log4j2: 2.20.0 –> <!– ============================================== ========== –> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.20.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.20.0</version> <exclusions> <exclusion> <artifactId>log4j-api</artifactId> <groupId>org.apache.logging.log4j</groupId> </exclusion> </exclusions> […]

The function of log framework Slf4j and its implementation principle

Directory 1 Design Pattern Facade Pattern 2 slf4j source code analysis 1 Design Pattern Facade Pattern Detailed explanation and application of facade pattern and decorator pattern of design patterns: https://blog.csdn.net/ZGL_cyy/article/details/129073521 slf4j is a typical application of the facade pattern, so before talking about slf4j, let us briefly review the facade pattern. The core of the […]

Java logging framework: the role of slf4j and its implementation principle

Table of Contents 1. A brief introduction to the facade model 2. slf4j 1. Why use slf4j 2. slf4j application examples 3. slf4j implementation principle Summarize 1. A brief introduction to the facade mode slf4j is a typical application of the facade pattern, so before talking about slf4j, let us briefly review the facade pattern. […]

Mybatis-plus @slf4j logback

mybatis-plus uses @slf4j logback to print logs to the console and log files Logback configuration part reference: logback configuration My application configuration file is in yml format # mybatis-plus mybatis-plus: global-config: db-config: id-type: auto configuration: log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl # log log logging: level: com.example: debug org.springframework: warn config: It may be related to my mybatis-plus version. […]

SLF4J Log Binding Principle Analysis

Foreword I have been working on a project recently, and I actually know about log conflicts, but it involves MDC NDC data transmission. When the log framework conflicts, MDC and NDC will become invalid. Here is the process of binding MDC of slf4j-api, which is analyzed by the way. The reason why the log conflict […]

How to integrate log framework SLF4J, Log4j in Spring Boot

Article directory Specific steps appendix The author’s operating environment: Spring Cloud Alibaba: 2022.0.0.0-RC2 Spring Cloud: 2022.0.0 Spring Boot: 3.0.2 Nacos 2.2.3 Maven 3.8.3 JDK 17.0.7 IntelliJ IDEA 2022.3.1 (Ultimate Edition) Concrete steps Because Spring Boot has built-in Logback, Logback needs to be removed first. The removal method is to remove Logback from the Spring Boot […]

Use the Slf4j log framework in the Lombok plug-in in the SpringBoot project

Preface: idea needs to install the lombok plug-in, because the @Slf4j annotation is added to the plug-in, which can translate @Slf4j into private static final org.slf4j.Logger logger = LoggerFactory.getLogger(this.XXX.class); Springboot itself has a built-in slf4j logging framework, so there is no need to refer to slf4j dependencies separately. 1. Getting Started 1. Add lombok dependency […]