Spring Boot logback configuration

First introduce it in the .pom file <!– HikariCP –> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>5.0.1</version> </dependency> <!– Slf4j –> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.32</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.32</version> </dependency> Create a new logback.xml file in resources with the following contents: <?xml version=”1.0″ encoding=”UTF-8″?> <!– The log levels from low to high are TRACE < DEBUG < […]

The impact of disk full on log printing (Logback)

Background In our production environment, a service alarmed in the middle of the night: the remaining disk space is less than 10%, please deal with it in time. After investigation, it was found that it was a newly launched function. It was caused by too many logs. There are many solutions, so I won’t go […]

Springboot project log4j and logback Jar package conflict problem

Exception information keywords: SLF4J: Class path contains multiple SLF4J bindings. ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:14 – no applicable action for [properties], current ElementPath is [[configuration][properties]] Detailed exception information: Connected to the target VM, address: ‘127.0.0.1:52687’, transport: ‘socket’ SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/xx/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/ slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/xx/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.17.2/log4j-slf4j-impl-2.17.2 .jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: […]

springboot log management logback

1. Introduction to logback In springboot, any spring-boot-starter-* will import a spring-boot-starter-logging starter dependency by default. The logback log is integrated by default. You can add log-related configurations in the application.yml of the project, or you can Directly specify the log configuration file for configuration. 2. How to integrate logback 2.1, springboot method Any spring-boot-starter-* […]

logback spring configuration

import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; private static final Log log = LogFactory.getLog(PrepareDataWorker.class); <?xml version=”1.0″ encoding=”UTF-8″?> <!– The log levels from low to high are TRACE < DEBUG < INFO < WARN < ERROR < FATAL. If set to WARN, no information lower than WARN will be output –> <!– scan: When this attribute is set to […]

Log4j2 or logback configuration template enables flexible output of service names

Introduction When we use log4j2 or logback to print logs, the service name must be added to the output content. Take log4j2 as an example: <!–Output console configuration–> <Console name=”Console” target=”SYSTEM_OUT”> <!– Format of output log –> <PatternLayout pattern=”server-case %d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L – %m%n”/> </Console> The service name is server-case, and the output content […]

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> […]

springboot integrates Logback and writes logs to the database

springboot integrates Logback to write logs to the database Introduce maven dependencies <!– logback log –> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.2.3</version> </dependency> Note: There is a Logback package inside springboot, but some class files were missing when I used it, so I mapped it separately. Create a table Logback has three […]

logback.xml configuration template (contains all configurations and comments, copy and paste directly and modify slightly as needed)

1. Overview Logback is a log management tool that can configure the storage path and log format of logs, classify logs and store them in specified files, set the size and storage period of log files (old logs will be deleted if they exceed the limit), and store logs on schedule or according to the […]

Java transparently transmits parameters to logback and customizes the log file name. Expired log files are automatically deleted

LogFilter Filter log interception intercepts log information that does not need to be printed, and only enters the ones with key parameters (filterReply = FilterReply.ACCEPT;). package com.***.***.filter; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.filter.Filter; import ch.qos.logback.core.spi.FilterReply; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * task log filter */ public class LogFilter extends Filter<ILoggingEvent> { private static Logger logger […]