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

Allow Json based layouts to output a root element

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.0, 2.14.1
    • Layouts
    • None

    Description

      This request applies to all all Json layouts:


      The layouts in this folder:

      https://github.com/apache/logging-log4j2/tree/master/log4j-layout-template-json/src/main/resources

      OutputĀ a structure that looks like this:

      {
        "instant": {
        },
        "thread": {
        },
        "level": {
        },
        "loggerName": {
        }
      

      Add a set of new templates and/or a config value to set a root element. Default could be "logEvent" but could be overridden to something else like "data":

      {
        "data": {
          "instant": {
          },
          "thread": {
          },
          "level": {
          },
          "loggerName": {
          }
      

      A root element (sometimes?) makes it easier to extract data in 3rd party tools like Splunk's spath command:

      https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath

      Maybe its as simple as calling withRootName?

      https://stackoverflow.com/questions/15936680/how-to-rename-root-key-in-json-serialization-with-jackson

      final ObjectWriter writer = mapper.writer().withRootName("rootName");
      

      Attachments

        Issue Links

          Activity

            People

              vy Volkan Yazici
              rgrabowski Ron Grabowski
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: