Log4j 2
  1. Log4j 2
  2. LOG4J2-84

Please provide means to disable NDC functionality on a global level.

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-beta2
    • Component/s: None
    • Labels:
      None

      Description

      Disabling NDC evaluation can have drastic effects on event size while sending them over the wire or dumping them to disk.

      When disabled, all calls to NDC-related methods will instead call NOP implementations, i.e. no ThreadLocals would be used at all.

        Issue Links

          Activity

          Hide
          Ralph Goers added a comment -

          I am not convinced that completely disabling the NDC is a good idea as it could lead to application breakage. However, I am convinced that having the ThreadContext stack be null in the LogEvent when there are no items in the stack is a very good idea.

          I plan on making that change and also plan on changing the stack stored in the LogEvent to be immutable. In addition, I plan on changing the ThreadContext API so that it doesn't use java.util.Stack but uses its own ContextStack interface. This will provide some freedom in changing the actual implementation of the stack.

          Show
          Ralph Goers added a comment - I am not convinced that completely disabling the NDC is a good idea as it could lead to application breakage. However, I am convinced that having the ThreadContext stack be null in the LogEvent when there are no items in the stack is a very good idea. I plan on making that change and also plan on changing the stack stored in the LogEvent to be immutable. In addition, I plan on changing the ThreadContext API so that it doesn't use java.util.Stack but uses its own ContextStack interface. This will provide some freedom in changing the actual implementation of the stack.
          Hide
          Ralph Goers added a comment -

          I have commit the change in revision 1389690 as described above. The stack in the LogEvent is now immutable and is null if the ThreadContext stack is empty.

          Show
          Ralph Goers added a comment - I have commit the change in revision 1389690 as described above. The stack in the LogEvent is now immutable and is null if the ThreadContext stack is empty.
          Hide
          Ralph Goers added a comment -

          Joern - are the changes made enough to resolve your concerns?

          Show
          Ralph Goers added a comment - Joern - are the changes made enough to resolve your concerns?
          Hide
          Joern Huxhorn added a comment -

          See comment in LOG4J2-83.

          Show
          Joern Huxhorn added a comment - See comment in LOG4J2-83 .
          Hide
          Ralph Goers added a comment -

          I have added support for setting system properties named "disableThreadContext", "disableThreadContextMap" , and "disableThreadContextStack". If disableThreadContext is set to true, pushes and puts will be ignored and no HashMaps or ContextStacks will be created. Similarly, if disableThreadContextMap is set to true then puts to the ThreadContextMap will be ignored and no Map will be created. Finally, if disableThreadContextStack is set to true then pushes will be ignored and no ContextStack will be created.

          When these properties are set the ThreadLocals will still be created but will never have any values in them.

          Show
          Ralph Goers added a comment - I have added support for setting system properties named "disableThreadContext", "disableThreadContextMap" , and "disableThreadContextStack". If disableThreadContext is set to true, pushes and puts will be ignored and no HashMaps or ContextStacks will be created. Similarly, if disableThreadContextMap is set to true then puts to the ThreadContextMap will be ignored and no Map will be created. Finally, if disableThreadContextStack is set to true then pushes will be ignored and no ContextStack will be created. When these properties are set the ThreadLocals will still be created but will never have any values in them.
          Hide
          Ralph Goers added a comment -

          Please verify the fix and close it. If it doesn't fully implement what is required feel free to reopen it.

          Show
          Ralph Goers added a comment - Please verify the fix and close it. If it doesn't fully implement what is required feel free to reopen it.
          Hide
          Joern Huxhorn added a comment -

          Looks good.

          Show
          Joern Huxhorn added a comment - Looks good.

            People

            • Assignee:
              Ralph Goers
              Reporter:
              Joern Huxhorn
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development