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

Messages logged inconsistently when using JsonTemplateLayout.

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.14.1
    • Fix Version/s: 3.0.0, 2.15.0
    • Component/s: JsonTemplateLayout
    • Labels:
      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

          Activity

            People

            • Assignee:
              vy Volkan Yazici
              Reporter:
              schubertf Schubert Fernandes

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment