Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2936

Add message parameters in JsonLayout

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.13.3
    • 2.14.0
    • Layouts

    Description

      By using the JsonLayout the following call:
       

      String invoiceNo = "A12345";
      long duration = 3999l;
      LOGGER.info("Invoice {} elaborated in {} milliseconds", invoceNo, duration);

      will produce something like this:
       

      {   // ...
         "message" : "Invoice A12345 elaborated in 3999 milliseconds"
         // ...
      }

      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:

      {   // ...
         "message" : "Invoice A12345 elaborated in 3999 milliseconds"
         "params" : {
                "p0" : "A12345"
                "p1" : "3999"
          }
         // ...
      }

      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.

      Attachments

        Activity

          People

            vy Volkan Yazici
            diepet Diego Pettisani
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: