You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2020/11/06 12:31:00 UTC
[jira] [Commented] (LOG4J2-2936) Add message parameters in
JsonLayout
[ https://issues.apache.org/jira/browse/LOG4J2-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17227372#comment-17227372 ]
ASF subversion and git services commented on LOG4J2-2936:
---------------------------------------------------------
Commit 97a464fbe9349d24ba24340e5a72d933fa0b5d72 in logging-log4j2's branch refs/heads/release-2.x from Volkan Yazici
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=97a464f ]
LOG4J2-2936 Add message parameter resolver to JSON template layout.
> 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
> Priority: Major
> Labels: JsonLayout
>
> 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)