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

Support default value for missing key in map-based pattern

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      %X

      {key} and %K{key}

      render the value found for key in the thread context map or MapMessage, respectively. If the key is not contained in the map, the pattern evaluates to "" (empty string).
      A default value for missing values can currently only be defined by using $${ctx:key} and defining a property named "key" with the desired default value. Drawbacks: ${ctx:key} has to be parsed and evaluated for each message and the pattern does not support conversion specifiers (for alignment, fixed width, etc).
      The proposed improvement would be to support an optional default value that can be specified in the pattern, e.g. %X

      {key:-defaultValue}

      Attachments

        1. log4j2-418.patch
          12 kB
          Oliver Flege

        Issue Links

          Activity

            People

              Unassigned Unassigned
              oliver.f Oliver Flege
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: