简体   繁体   中英

Log4j2 JSONLayout gives error

i am try to config my log4j2 but i always get this errors:

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

The last error is for "mylevs" appender. Result: i get JSON format logs for warn and error, but for mylevel there is usual data format. What could cause this errors?

My log4j2.xml config:

<?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: i am following documentation guide. And this text to pass this quastion, so please don't read this.

You can define exactly one layout per appender. But you are defining two layouts for each one. Try removing one layout from each of your appenders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM