简体   繁体   English

如何自定义或删除 Log4j2 中的默认属性 - JSON 布局

[英]How to customize or remove default attributes in Log4j2 - JSON Layout

In Spring Boot 2 application I have configured Log4j2 with JsonLayout like belowSpring Boot 2应用程序中,我已经使用JsonLayout配置了Log4j2 ,如下所示

    ....

    <Appenders>
        <Console name="ConsoleJSONAppender" target="SYSTEM_OUT">
            <JsonLayout complete="false" compact="false">
            </JsonLayout>
        </Console>
    </Appenders> 
    <Logger name="CONSOLE_JSON_APPENDER" level="INFO" additivity="false">
        <AppenderRef ref="ConsoleJSONAppender" />
    </Logger>

    .....

and I got output like below我得到了 output 如下所示

    {
            "timeMillis" : 1496306649058,
            "thread" : "main",
            "level" : "INFO",
            "loggerName" : "ConsoleJSONAppender",
            "message" : "Json Message",
            "endOfBatch" : false,
            "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
            "threadId" : 1,
            "threadPriority" : 5
    }

Output is fine but I don't want attributes like "endofBatch", "threadPriority" and others but it is getting displayed in logs, how to avoid unwanted (default) attributes in JsonLayout based logs . Output 很好,但我不想要“endofBatch”、“threadPriority”等属性,但它会显示在日志中,如何避免基于JsonLayout的日志中不需要的(默认)属性

If you want to log only level and loggerName than customize like below in your configuration file.如果您只想记录levelloggerName而不是像下面在配置文件中自定义。

...
<PatternLayout>
    <pattern>{"level":"%p","loggerName":"%c"}</pattern>
</PatternLayout>
...

The parameter are described at here .该参数在此处进行了描述。 Find Patterns at Pattern Layout .Pattern Layout中查找Patterns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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