我尝试配置我的log4j2,但我总是得到这个错误:
2017-11-06 01:14:15,454 RMI TCP Connection(3)-127.0.0.1 ERROR appender RollingFile has no parameter that matches element PatternLayout
2017-11-06 01:14:15,478 RMI TCP Connection(3)-127.0.0.1 ERROR appender RollingFile has no parameter that matches element PatternLayout
2017-11-06 01:14:15,484 RMI TCP Connection(3)-127.0.0.1 ERROR appender RollingFile has no parameter that matches element JSONLayout
最后一个错误是“mylevs”appender。结果:我得到警告和错误的JSON格式日志,但对于mylevel,有通常的数据格式。 什么可能导致这个错误?
我的log4j2.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" strict="true" name="XMLConfigTest"
packages="org.apache.logging.log4j.test">
<Properties>
<Property name="logsPath">F:/Projects/Work/DSTULib/logs/ULS</Property>
</Properties>
<CustomLevel name="MYLEVEL" intLevel="700" />
<Appenders>
<RollingFile name="errors" fileName="${logsPath}/errors.log"
filePattern="'.'%d{yyyy-MM-dd}'.log.zip'">
<JSONLayout compact="true" eventEol="true"/>
<PatternLayout>
<Pattern>%n%n%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
<Filters>
<ThresholdFilter level="FATAL" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</RollingFile>
<RollingFile name="warns" fileName="${logsPath}/warns.log"
filePattern="'.'%d{yyyy-MM-dd}'.log.zip'">
<JSONLayout compact="true" eventEol="true"/>
<PatternLayout>
<Pattern>%n%n%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
<Filters>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</RollingFile>
<RollingFile name="mylevs" fileName="${logsPath}/mylevel.log"
filePattern="'.'%d{yyyy-MM-dd}'.log.zip'">
<PatternLayout>
<Pattern>%n%n%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
<Filters>
<ThresholdFilter level="TRACE" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="MYLEVEL" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<JSONLayout compact="true" eventEol="true"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="mylevs" level="mylevel" />
<AppenderRef ref="errors" level="error"/>
<AppenderRef ref="warns" level="warn"/>
</Root>
</Loggers>
</Configuration>
PS:我正在关注文档指南。 而这篇文章要通过这个问题,所以请不要读这个。
答案 0 :(得分:0)
您可以为每个appender精确定义一个布局。但是您要为每个布局定义两个布局。尝试从每个appender中删除一个布局。