[Bug 291] New: Unusable with Logback-ContextSelectors.

http://bugzilla.slf4j.org/show_bug.cgi?id=291 Summary: Unusable with Logback-ContextSelectors. Product: SLF4J Version: 1.7.x Platform: PC OS/Version: Windows XP Status: NEW Severity: major Priority: P1 Component: log4j-over-slf4j AssignedTo: slf4j-dev@qos.ch ReportedBy: thomas.moeller@continentale.de 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. -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=291 Thomas Möller <thomas.moeller@continentale.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |thomas.moeller@continentale | |.de -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=291 Ceki Gulcu <listid@qos.ch> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |listid@qos.ch --- Comment #1 from Ceki Gulcu <listid@qos.ch> 2013-03-13 12:04:20 CET --- I see the problem. By the way, it exists with the slf4j-log4j binding as well when used with log4j's own context selection mechanism. As stated in [1] Unfortunately, for non-native implementations of the SLF4J API, namely with slf4j-log4j12, log4j's repository selector will not be able to do its job properly because slf4j-log4j12, a non-native SLF4J binding, will store logger instances in a map, short-circuiting context-dependent logger retrieval. For native SLF4J implementations, such as logback-classic, repository selectors will work as expected. I reckoned that since logback-context selection is an advanced feature, users would migrate their code to slf4j (instead of log4j). Removing the cache in Log4jLoggerFactory, would solve this problem but would imply that multiple (log4j-over-slf4j) Logger instances would be created, all wrapping an slf4j loggers. I suppose this would not be such a big deal after all. [1] http://www.slf4j.org/faq.html#declared_static -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@qos.ch