Can’t handle the log? Teach you step by step how to use Log4j2

Todaywewillexplainoneoftheyoungestlogplug-ins,namelyLog4j2.Log4j2iscurrentlywidelyusedandhasimprovedalotcomparedtoitspredecessorLog4jinallaspects.However,ifyouwanttomakegooduseofit,youstillneedtogothroughacertainamountoflearning,especiallytounderstanditsvariousconfigurations.Let’sstarttoday’sprogress.leveljourney. 1.Introducedependencies WecanusethefollowingdependenciestointroducetheLog4j2frameworkintoourproject <!–ThelogfacadethatcomeswithLog4j2–> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.13.3</version> </dependency> <!–Log4j2specificlogimplementation–> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.13.3</version> </dependency> Ofcourse,asmentionedinthelastissue,Irecommenddirectlyusingthefollowinglog4j-slf4j-implpackage <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.13.3</version> </dependency> ThispackagecontainstheimplementationofLog4j2andcanalsointerfacewithSLF4J,makingitmoresuitableforapplicationinprojects. 2.Configurationfileexample Let’slookatthefollowingconfigurationfile:log4j2.xml <?xmlversion=”1.0″encoding=”UTF-8″?> <Configurationstatus=”DEBUG”monitorInterval=”30″> <!–Outputformat–> <PatternLayoutpattern=”%d{yyyy-MM-ddHH:mm:ss.SSS}-[%t]%-5level%logger{36}-%msg%n”/> <Appenders> <!–Consoleoutput–> <Consolename=”Console”target=”SYSTEM_OUT”> <!–Filter–> <ThresholdFilterlevel=”INFO”onMatch=”ACCEPT”onMismatch=”DENY”/> <!–BufferbufferSize,thedefaultvalueis256,canbeadjustedtobetween1-256–> <Bufferedmode=”ONCE”bufferSize=”256″/> </Console> <!–Fileoutput–> <RollingFilename=”RollingFile”fileName=”/path/to/logs/test.log”filePattern=”/path/to/logs/$${date:yyyy-MM}/test-%d{yyyy-MM-dd}-%i.log”> <ThresholdFilterlevel=”INFO”onMatch=”ACCEPT”onMismatch=”DENY”/> <!–Outputformat–> <PatternLayoutpattern=”%d{yyyy-MM-ddHH:mm:ss.SSS}[%t]%-5level%logger{36}-%msg%n”/> <!–Triggerstrategy–> <Policies> <!–Scrollbytime–> <TimeBasedTriggeringPolicy/> <!–Scrollbyfilesize,set10MBhere–> <SizeBasedTriggeringPolicysize=”10MB”/> </Policies> <!–Rollingstrategy–> <DefaultRolloverStrategymax=”10″/> </RollingFile> </Appenders> <Loggers> <!–Defaultlog–> <Rootlevel=”INFO”> […]

springboot log management log4j2

1. Introduction to log4j2 Apache Log4j2 is an upgrade to Log4j that provides significant improvements over its predecessor Log4j 1.x and provides many of the improvements available in Logback while fixing some issues in the Logback architecture. It is known as the best Java logging framework at present. 2. How to introduce log4j2 into the […]

Flink Log4j 2.x uses Filter to filter log types

Flink Log4j 2.x uses Filter to filter log types (differentiate between INFO and ERROR) Article directory Flink Log4j 2.x uses Filter to filter log types (differentiate between INFO and ERROR) ThresholdFilter LevelMatchFilter Log level: ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF log4j official website: https://logging.apache.org/log4j/2.x/index.html ThresholdFilter In […]

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

Exceptions and log4j2 usage

Exception 1. Concept An abnormal event that occurs during the running of the program and the event can be handled will interrupt the running program. 2. Classification Error: represents a system-level error (a serious problem) Once a problem occurs in the system, Sun will encapsulate these errors into Error objects. Exception: represents possible problems that […]

springboot log management log4j2

1. Introduction to log4j2 Apache Log4j2 is an upgrade to Log4j that provides significant improvements over its predecessor Log4j 1.x and provides many of the improvements available in Logback while fixing some issues in the Logback architecture. It is known as the best Java logging framework at present. 2. How to introduce log4j2 into the […]

Mybatis log (Log4j2)

Previously we introduced the use of JDK Log and Apache Commons Logging to print Mybatis runtime logs; in this article we introduce the use of Log4j2 to print Mybatis runtime logs. If you don’t know much about using JDK Log and Apache Commons Logging in Mybatis to print Mybatis runtime logs, you can refer to: […]

ssm integrates configuration files and related analysis of mybatis, log4j and MySQL database, webmvc, shiro, dbcp, etc.

1pom file <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=” http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>com.xzp</groupId> <artifactId>wuliu</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <!–Configured a Maven War plug-in named “maven-war-plugin” to solve the problem of Cannot access defaults field of Properties –> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.1</version> </plugin> </plugins> </build> <!–Configured a Maven War plug-in named “maven-war-plugin” to solve the problem of Cannot access […]

Log4j maven dependency configuration

When working on projects, we often need to print logs for applications. LOG4J is our best choice. When project management is built using maven, the pom.xml configuration is as follows <!–Log start–> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.25</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.25</version> <scope>test</scope> </dependency> <!–Log […]

Can’t handle the log? Teach you step by step how to use Log4j2

The path to growth as a programmer Internet/Programmer/Technology/Data Sharing focus on This article should take approximately 12 minutes to read. From: blog.csdn.net/u011709538/article/details/132459143 Today we will explain one of the youngest log plug-ins, namely Log4j2. Log4j2 is currently widely used and has improved a lot compared to its predecessor Log4j in all aspects. However, if you […]