实施log4j2时,我遇到了ERROR类类org.apache.logging.log4j.core.pattern.MapPatternConverter无法包含多个静态newInstance方法
val final logger:org.apache.logging.log4j.Logger = LogManager.getLogger(Logger.class);
val mapMessage:StringMapMessage = new StringMapMessage();
class MyClass(){
//Append to mapMessage
def someMethod(message:String ){
mapMessage.with("Key1", Objects.requireNonNull("someValue--1", "defaultValue"));
}
//Append to mapMessage
def doSomeMoreMethod(key:String messgae:String) {
mapMessage.with("Key2", Objects.requireNonNull("someValue--2", "defaultValue"));
}
def readyToLog(){
//sending the map to the logger
logger.info(mapMessage)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="%date{ISO8601}Z %level %map{Key1} %map{Key2} %n"
/>
</Console>
</Appenders>
<Loggers>
<Root level="debug" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
预期
[INFO] 2019-04-10 13:08:40.687 [main-ScalaTest-running-YourYourYourApplicationTest] MyClass $-someValue--1 someValue--2
实际 PatternLayout无法转换为stringMapMessage给出的模式
2019-04-10 13:08:40,559 main-ScalaTest-running-YourYourYourApplicationTest ERROR Class类 org.apache.logging.log4j.core.pattern.MapPatternConverter无法 包含多个静态newInstance方法2019-04-10 13:08:40,560 main-ScalaTest-running-YourYourYourApplicationTest错误无法识别 转换说明符[地图]从转换中的位置68开始 图案。 [INFO] 2019-04-10 13:08:40.681 [main-ScalaTest-running-YourYourApplicationTest] MyClass $-%map
[错误] 2019-04-10 13:08:40.687 [main-ScalaTest-running-YourYourApplicationTest] MyClass $-%map