Log4J2 JSONLAYOUT如何添加自定义参数 [英] Log4J2 JSONLAYOUT How to add custom Parameters

查看:2028
本文介绍了Log4J2 JSONLAYOUT如何添加自定义参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Log4j2的JSONLAYOUT中添加自定义参数?

How to add customized parameters to Log4j2’s JSONLAYOUT?

还可以在JSONLAYOUT的message元素中添加模式吗?

Also is there a way to add pattern to the JSONLAYOUT’s message element?

我已经尝试过此处列出的选项->
logging.apache.org/log4j/2.x/manual/layouts.html#JSONLayout

I have tried the options listed here ->
logging.apache.org/log4j/2.x/manual/layouts.html#JSONLayout

请帮助!

推荐答案

解决方案是显式添加log4j2的2.10.0版本.此版本支持JSONLayout中的自定义参数!

Solution is to explicitly add log4j2’s 2.10.0 version. This version supports custom parameter in JSONLayout!

<Appenders>

    <Console name="Console" target="SYSTEM_OUT">
        <JSONLayout compact="true" eventEol="true">
            <KeyValuePair key="application" value="${sys:com.example.appname}"/>
        </JSONLayout>
    </Console>
    <Async name="AsyncAppender" bufferSize="80">
        <AppenderRef ref="Console"/>
    </Async>

</Appenders>

这篇关于Log4J2 JSONLAYOUT如何添加自定义参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆