可以通过一下四种方法之一配置Log4j2
Log4j初始化时按照一下顺序寻找配置
log4j.configurationFile
, 如果找到将使用它作为配置文件log4j2-test.properties
log4j2-test.yam
或者log4j2-test.yml
log4j2-test.json
或者log4j2-test.jsn
log4j2-test.xml
-test
的配置文件默认配置:
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
Level.ERROR
对应默认配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
</dependencies>