You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Volkan Yazici (Jira)" <ji...@apache.org> on 2020/11/06 12:33:00 UTC
[jira] [Closed] (LOG4J2-2936) Add message parameters in JsonLayout
[ https://issues.apache.org/jira/browse/LOG4J2-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Volkan Yazici closed LOG4J2-2936.
---------------------------------
> Add message parameters in JsonLayout
> ------------------------------------
>
> Key: LOG4J2-2936
> URL: https://issues.apache.org/jira/browse/LOG4J2-2936
> Project: Log4j 2
> Issue Type: New Feature
> Components: Layouts
> Affects Versions: 2.13.3
> Reporter: Diego Pettisani
> Assignee: Volkan Yazici
> Priority: Major
> Labels: JsonLayout
> Fix For: 2.14.0
>
>
> By using the JsonLayout the following call:
>
> {code:java}
> String invoiceNo = "A12345";
> long duration = 3999l;
> LOGGER.info("Invoice {} elaborated in {} milliseconds", invoceNo, duration);{code}
> will produce something like this:
>
> {code:json}
> { // ...
> "message" : "Invoice A12345 elaborated in 3999 milliseconds"
> // ...
> }{code}
> And for extracting the {{invoceNo}} and {{duration}} values from a log collector tool (e.g. Elastic) it is needed to play with patterns and regex hard to maintain in the log shipper (e.g. Fluentd).
> It could be very helpful to add a new boolean configuration property in the JsonLayout element in order to enable the printing of the message parameters as Json fields.
> After enabled this new property (e.g. {{parameters=true}}), the output JSON should be something like this:
> {code:json}
> { // ...
> "message" : "Invoice A12345 elaborated in 3999 milliseconds"
> "params" : {
> "p0" : "A12345"
> "p1" : "3999"
> }
> // ...
> }{code}
> In this way, it will be possible to extract that values very easily from the log collector tool, without implementing ad-hoc pattern/regex in the log shipper.
> This feature could be especially useful for legacy code hard to change that uses SLF4J APIs for logging: extracting values from that kind of messages will be a piece of cake.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)