@[toc]
- Configuration must depend on packagesYou can find the latest version yourself
<! -- Lombok dependencies --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok-version}</version> <scope>provided</scope> </dependency> <! -- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.11.1</version> </dependency> <! -- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.11.1</version> </dependency> <! - slf4j and bridging log4j2 log4j) - slf4j - impl, role is to use slf4j API, but the underlying implementation is based on log4j2 - > <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.11.1</version> </dependency> <! -- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> Copy the code
- Configure the log4j2.xml file
The log4j2.xml file can be configured as XML, and also supports the properties file format. Here I use XML. This file is stored in the project SRC /main/resources, and can be automatically read because of the file name. xml
< TimeBasedTriggeringPolicy interval = “1” modulate = “true” / >
< SizeBasedTriggeringPolicy size = “5 MB” / > < / Policies >
- Use the @slf4J annotation on the class in code and then use the log.info form internally