You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Marcus Thiesen (JIRA)" <ji...@apache.org> on 2015/09/10 11:16:45 UTC

[jira] [Created] (LOG4J2-1117) OutputStreamManager in ConsoleAppender leaking managers?

Marcus Thiesen created LOG4J2-1117:
--------------------------------------

             Summary: OutputStreamManager in ConsoleAppender leaking managers?
                 Key: LOG4J2-1117
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1117
             Project: Log4j 2
          Issue Type: Bug
    Affects Versions: 2.1
            Reporter: Marcus Thiesen
            Priority: Minor


I'm actually confused about the intention here, so this is more a question than a bug report, though I'm quite sure that something is wrong here.

I ran into this issue while writing unit tests for a custom layout and using InitialLoggerContext to setup my logging. I was expecting to always get a fresh start with my actual logger. And I always set a new custom PrintStream for System.out in order to capture the finished output. 
That just worked once, even when I set "follow" ("If true will follow changes to the underlying output stream.") on the console appender, due to the caching in the AbstractManager/OutputSteamManager output.

The issue is that ConsoleAppender.getManager does the following:
OutputStreamManager.getManager(target.name() + '.' + follow, new FactoryData(os, type, layout), factory);

So the key that ends up in AbstractManager.MAP is something like "SYSTEM_OUT.true". ConsoleAppenders.ConsoleManagerFactory just uses data.type as the name for the manager, so this will be something like "SYSTEM_OUT" in this case.

But AbstractManager.release uses the "name" field of the Manager for removing from the map, thus an entry with "SYSTEM_OUT.true" will never be removed, which leads to the issue that changes to System.out will not be visible for the ConsoleAppender.




 





--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org