You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Daniel Brugger (JIRA)" <ji...@apache.org> on 2018/11/14 07:39:00 UTC

[jira] [Created] (LOG4J2-2506) MutableLogEvent references to other objects are cleared after each use

Daniel Brugger created LOG4J2-2506:
--------------------------------------

             Summary: MutableLogEvent references to other objects are cleared after each use
                 Key: LOG4J2-2506
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2506
             Project: Log4j 2
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 2.11.1
            Reporter: Daniel Brugger


The changes made in Log4J 2.11.1 / LOG4J2-2269 cause serious problems on our side: external references on {{MutableLogEvent}} object, like the {{ContextMap}} or even Strings, are cleared on existing LogEvent objects when a new LogEvent gets logged. We put additional information into the {{ContextMap}} of the {{MutableLogEvent}}, and we cache these objects for a while before we output them.

You might ask why we need to cache LogEvents. We often process large amount of data in our framework and this might produce thousands of identical log messages. So we wrote an {{Appender}} which caches distinct messages in order to eliminate duplicates. At the end of a batch the {{Appender}} gets flushed and the unique messages along with their counter are forwarded to another {{Appender}}. The counter is maintained in the {{ContextMap}} of the cached event, and this counter is later used in the message {{Layout}}. So we cannot simply "put it somewhere else", since the missing counter is not the only thing, after calling the {{clear()}} method all information is lost.

As a workaround (hack?) we subclassed {{MutableLogEvent}} and overwrote the {{clear()}} method. Works for this time, but we'd prefer a cleaner solution.

So we ask to turn back the wheel and reestablish the solution how it was in 2.11.0 (and at least since ten years). Or provide a backward compatible solution. As an idea, one might implement a flag like {{MutableLogEvent.clearReferencesAfterLogging}} and only if it's {{true}} the {{clear()}} method gets called. By default - and in order to stay backward compatible - this flag could be {{false}}.

Thanks.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)