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

OutputStreamManager in ConsoleAppender leaking managers

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.4
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              garydgregory Gary Gregory
              Reporter:
              marcus@thiesen.org Marcus Thiesen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: