[
https://issues.apache.org/jira/browse/LOG4J2-3013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17277895#comment-17277895
]
Volkan Yazici commented on LOG4J2-3013:
---------------------------------------
First, I think we have a misunderstanding. In this ticket you created,
description says {{JsonLayout}}, but selected _Component/s_ point to
{{JsonTemplateLayout}}, which is a successor to the {{JsonLayout}}. Further, my
first comment also refers {{JsonTemplateLayout}}, but your follow-up comment
still uses {{JsonLayout}}.
I strongly advise you to use {{JsonTemplateLayout}}, *not* {{JsonLayout}} –
which is to be removed in 3.0.0 release.
You can use the following JSON configuration to employ {{JsonTemplateLayout}}
with additional fields:
{code:json}
{
"JsonTemplateLayout": {
"eventTemplate":
"{\"@timestamp\":{\"$resolver\":\"timestamp\",\"pattern\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\",\"timeZone\":\"UTC\"}},\"log.level\":{\"$resolver\":\"level\",\"field\":\"name\"},\"message\":{\"$resolver\":\"message\",\"stringified\":true},\"process.thread.name\":{\"$resolver\":\"thread\",\"field\":\"name\"},\"log.logger\":{\"$resolver\":\"logger\",\"field\":\"name\"},\"labels\":{\"$resolver\":\"mdc\",\"flatten\":true,\"stringified\":true},\"tags\":{\"$resolver\":\"ndc\"},\"error.type\":{\"$resolver\":\"exception\",\"field\":\"className\"},\"error.message\":{\"$resolver\":\"exception\",\"field\":\"message\"},\"error.stack_trace\":{\"$resolver\":\"exception\",\"field\":\"stackTrace\",\"stackTrace\":{\"stringified\":true}},\"additionalFieldKey\":\"additionalFieldValue\"}"
}
}
{code}
Above giant {{eventTemplate}} literal is copy-pasted from {{EcsLayout.json}},
which is distributed with the {{log4j-layout-template-json}} artifact. The only
difference is the {{,\"additionalFieldKey\":\"additionalFieldValue\"}} part I
have added myself. Once 2.14.1 is released, {{eventTemplateAdditionalField}}
bug will be fixed and the above configuration can be simplified as follows:
{code:json}
{
"JsonTemplateLayout": {
"eventTemplateUri": "classpath:EcsLayout.json",
"eventTemplateAdditionalField": [{"key": "additionalFieldKey", "value":
"additionalFieldValue"}]
}
}
{code}
> Impossible to specify AdditionalField of JsonLayout in json config
> ------------------------------------------------------------------
>
> Key: LOG4J2-3013
> URL: https://issues.apache.org/jira/browse/LOG4J2-3013
> Project: Log4j 2
> Issue Type: Bug
> Components: Configurators, JsonTemplateLayout
> Affects Versions: 2.14.0
> Environment: log4j2 2.14.0 on Oracle JDK 14
> Reporter: expert
> Assignee: Volkan Yazici
> Priority: Major
>
> Applogozies I have to resort to creating an issue but I think it's major
> problem for users who want to use new json config.
> Could you please demostrate how to specify AdditionalField of JsonLayout in
> json config ?
> Ideally it would be good to see in documentation example of configuration for
> every type of plugin annotation (PluginBuilderAttribute, PluginElement and
> etc.)
> Unfortunatelly I couldnt'n figure out how to set additionalFields after two
> hours of heavy debugging in log4j2 sources.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)