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

Support external serializers (e.g., Jackson) JsonTemplateLayout

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: In Progress
    • Minor
    • Resolution: Unresolved
    • 2.14.1
    • None
    • JsonTemplateLayout
    • None

    Description

      When using JsonTemplateLayout is there a way to output composite objects as JSON?
      It looks like any composite objects are output as simple strings with the value generated by the .toString() method of the Java object.
      Is there an option to output JSON instead, possibly using org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper ?

      It is currently possible to do this by converting the object into a java.util.Map before supplying it to the logging framework but it would be nice if the logging framework did this out of the box if an option is turned on as it is not always possible to do this (e.g. with objects on the MDC/NDC).

      This should apply to composite objects logged from...

      1. The thread context map (MDC).
      2. The thread context stack (NDC).
      3. Message parameters
      4. anywhere else that I may have missed.

      See the differences between the two log messages generated in the attached project.

      Attachments

        1. log4j.json.event.layout.zip
          19 kB
          Schubert Fernandes

        Activity

          People

            vy Volkan Yazici
            schubertf Schubert Fernandes
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated: