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

Messages logged inconsistently when using JsonTemplateLayout.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.14.1
    • 3.0.0, 2.15.0
    • JsonTemplateLayout
    • None

    Description

      When using the JsonTemplateLayout and configuring the message with a fallbackKey...

        "message": {
          "$resolver": "message",
          "fallbackKey": "asString"
        }
      

      the fallbackKey is not consistently used.
      When logging via org.apache.log4j.Category.info(Object) the message string is logged directly without using the property defined in fallbackKey, e.g.

      {"timestamp":"2021-04-21T14:25:27.625+01:00","loggerName":"explore.log4j.json.template.layout.Main","level":"INFO","message":"Message logged using org.apache.log4j.Category.info(Object)"}

      but when logging using org.apache.logging.log4j.Logger.info(String) the message is correctly logged in the asString property as required, i.e.

      {"timestamp":"2021-04-21T14:25:27.628+01:00","loggerName":"explore.log4j.json.template.layout.Main","level":"INFO","message":{"asString":"Message logged using org.apache.logging.log4j.Logger.info(String)"}}

      Sample Maven project attached to reproduce.

      Attachments

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

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: