2.0版本的文件命名为log4j2.properties,文件位置放置在classpath下,文件内容如下
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
rootLogger.level = debug
rootLogger.appenderRef.stdout.ref = STDOUT
pom.xml中相关依赖的加入
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
测试:
Logger logger = LogManager.getLogger();
logger.info("log info");
logger.warn("log warn");
logger.error("error info");
logger.debug("debug info");
网友评论