You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Diego Pettisani (Jira)" <ji...@apache.org> on 2020/09/24 21:50:00 UTC

[jira] [Created] (LOG4J2-2936) Add message parameters in JsonLayout

Diego Pettisani created LOG4J2-2936:
---------------------------------------

             Summary: 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


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 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 and some ad-hoc special configurations are needed for extracting useful data.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)