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

NdcPatternConverter isn't GC-free

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.8, 2.8.1
    • None
    • Pattern Converters
    • None

    Description

      The issue (LOG4J2-1715) sought to make the NdcPatternConverter GC-free, but it looks as though that work doesn't get used. The interface StringBuilderFormattable is never checked for when formatting in the convertor, and as a result the builder is left to fend for itself, resorting ultimately to String.valueOf.

      I believe the code should end up looking something like this.

      NdcPatternConverter.java
      public void format(final LogEvent event, final StringBuilder toAppendTo) {
          ThreadContext.ContextStack stack = event.getContextStack();
          if (stack instanceof StringBuilderFormattable) {
              ((StringBuilderFormattable) stack).formatTo(toAppendTo);
          } else {
               toAppendTo.append(stack);
          }
      }
      

      Happy to submit a patch if this makes sense or for someone else to. Still getting my head around Log4j internals so confirmation of this would be helpful.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mal Mal Graty
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: