Introduction
Simple Logging Facade for Java (SLF4J)
The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.
Configuation
pom.xml
1 | <properties> |
log4j2.xml
1 | "1.0" encoding="UTF-8" xml version= |
注:如果不添加additivity=”false”属性,输出重复log
Enable AsyncLogger
JVM启动参数(boot.ini)加上“-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector”
classpath中添加文件“log4j2.component.properties”,文件增加以下内容:“Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector”
手工指定部分Logger采用异步方式log4j2.xml配置文件中使用AsyncRoot/AsyncLogger替代Root/Logger
Usage
1 | val logger = LogManager.getLogger() |
1 | -Dlog4j.configurationFile=log4j2-dev.xml |