[英]Using log4j2 gelflayout, is there a way to suppress adding the underscore in the final payload
We are trying to set a custom field but the GelfLayout with log4j seems to inject an under score when using the Key Value configuration.我们正在尝试设置一个自定义字段,但是在使用键值配置时,带有 log4j 的 GelfLayout 似乎注入了一个低分。 Is there a way to override that.
有没有办法覆盖它。
Here is the configuration:这是配置:
<Console name="GreyLogSysOut" target="SYSTEM_OUT">
<GelfLayout compressionType="OFF" includeStackTrace="true" includeThreadContext="true" >
<KeyValuePair key="host" value="$${ctx:mdchost}" />
<KeyValuePair key="level" value="3" />
<KeyValuePair key="GL_timestamp" value="${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}" />
<KeyValuePair key="GL_timestamp" value="${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}" />
<KeyValuePair key="GL_environment" value="$${ctx:mdcenv}" />
<KeyValuePair key="GL_userid" value="$${ctx:mdcLogAgentId}" />
<KeyValuePair key="GL_process" value="PriPolApps" />
<KeyValuePair key="GL_appclass" value="PriPolApps" />
<KeyValuePair key="GL_appid" value="$${ctx:mdcappid}" />
<KeyValuePair key="GL_sessionId" value="$${ctx:mdcLogSessionId}" />
<KeyValuePair key="GL_correlationId" value="$${ctx:correlationId}" />
<KeyValuePair key="GL_logdir" value="${sys:appserver.Name}" />
<KeyValuePair key="GL_jvm" value="$${ctx:jvm}" />
</GelfLayout>
</Console>
But the output injects underscore, is there a way to remove.但是output注入下划线,有没有办法去掉。
"_GL_correlationId":"${ctx:correlationId}", "_GL_logdir":"/usr/local/pfs/logs/server6/", "_GL_jvm":"${ctx:jvm}", "_GL_correlationId":"${ctx:correlationId}", "_GL_logdir":"/usr/local/pfs/logs/server6/", "_GL_jvm":"${ctx:jvm}",
Yes, there is a way to remove this.是的,有一种方法可以删除它。 The answer is quite straightforward.
答案很简单。
Just use the Custom GelfLayout
.只需使用
Custom GelfLayout
。 You can use the configuration from above but remove the includeStackTrace
, includeThreadContext
and customFields
line:您可以使用上面的配置,但删除
includeStackTrace
、 includeThreadContext
和customFields
行:
<GelfLayout compressionType="OFF" includeStackTrace="true" includeThreadContext="true" >
<KeyValuePair key="host" value="$${ctx:mdchost}" />
<KeyValuePair key="level" value="3" />
<KeyValuePair key="GL_timestamp" value="${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}" />
<KeyValuePair key="GL_environment" value="$${ctx:mdcenv}" />
<KeyValuePair key="GL_userid" value="$${ctx:mdcLogAgentId}" />
</GelfLayout>
And you will have this output:你将拥有这个 output:
"_GL_correlationId":"${ctx:correlationId}", "_GL_logdir":"/usr/local/pfs/logs/server6/", "_GL_jvm":"${ctx:jvm}",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.