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

Custom fields in JsonLayout should not overwrite existing fields

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Layouts
    • None

    Description

      When I added custom fields to the JsonLayout, I was expecting these fields to be added to the original message. What I instead observed was the following.

       

      The original message, of format:

       

      { "thread" : "main", "level" : "INFO", "loggerName" : "com.ibm.sterling.afc.common.external.PrometheusServlet", "message" : "Started the Prometheus Metrics Server", "endOfBatch" : true, "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger", "contextMap" : \{ }

      ,
      "instant" :

      { "epochSecond" : 1590165722, "nanoOfSecond" : 968000000 }

      ,
      "threadId" : 1,
      "threadPriority" : 5
      }
       

      Became the following format:

       

      { "logEvent" : "Started the Prometheus Metrics Server", "key1" : "value1", "key2" : "value2" }

       

       

      Is there a way to add additional fields to a JsonLayout without losing out on the other valuable information? The docs don't make this clear if so, and trial and error has been fruitless. If this isn't possible, then could this functionality be added?

       

      Thank you

      Attachments

        Activity

          People

            Unassigned Unassigned
            bullardla Luke Bullard
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: