[logback-user] Unable to use ContextSelector

Leonardo de Moura Rocha Lima llima at v2telecom.com.br
Wed May 30 17:59:25 CEST 2007

Hello, all.

I've been trying to use a ContextSelector to achieve the behavior of
JNDIContextSelector, but replacing JNDI lookups with MDC.get().
It did work and now I can have a new LoggerContext based on MDC. That way, I
can have new configuration options based on MDC variables. I changed the
StaticLoggerBinder implementation to use this new ContextSelector and the
first context is correctly get and used.

The problem that is stopping my progress is that I can't get to use more
than one context.
The StaticLoggerBinder.getLoggerFactory() is called once, and only once: in
startup. After that, I can't change the ILoggerFactory that's inside the
LoggerFactory, because it's static and only set in static { }. That way,
when I need to switch contexts, even if I change the current context inside
the ContextSelector, it won't be used by the LoggerFactory.
I even reproduced the calls from ContextSelectorFilter so that I set/unset
the current context, but no use.

I thought about using a wrapper ILoggerFactory, but it feels wrong, because
the JNDIContextSelector doesn't use anything else and is supposed to work.

What am I doing wrong? How do I use ContextSelectors outside what's
mentioned in logback manual?

Leonardo de Moura Rocha Lima
55 11 3094.3939

More information about the Logback-user mailing list