Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-282

Unusable with Logback-ContextSelectors.

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.7.x
    • log4j-over-slf4j
    • None
    • Operating System: Windows XP
      Platform: PC

    Description

      Log4j-Loggers are cached in static fields.

      See org.apache.log4j.Log4jLoggerFactory:

      public static synchronized Logger getLogger(String name) {
      if (log4jLoggers.containsKey(name))

      { return (org.apache.log4j.Logger) log4jLoggers.get(name); }

      else

      { Logger log4jLogger = new Logger(name); log4jLoggers.put(name, log4jLogger); return log4jLogger; }

      }

      A Log4j-Logger caches a reference to a Slf4j-Logger.

      See org.apache.log4j.Category:

      Category(String name) {
      this.name = name;
      slf4jLogger = LoggerFactory.getLogger(name);
      if (slf4jLogger instanceof LocationAwareLogger)

      { locationAwareLogger = (LocationAwareLogger) slf4jLogger; }

      }

      The problem is that the result of LoggerFactory.getLogger(name) is not cacheable because it could depend on Logback-ContextSelectors. One example: the JNDI-ContextSelector switches between different JNDI-Contexts. If the log4j-over-slf4j bridge jar is installed in a shared classloader the first request to getLogger() would tie the logger to the respective JNDI-Context.

      And it is not a solution to move the bridge jar to each web application because the context selector could switch e. g. between users.

      Attachments

        Activity

          People

            slf4j-dev SLF4J developers list
            thomoell Thomas Möller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: