public LoggerContext getLoggerContext() {
        String contextName = null;
        Context ctx = null;

        // First check if ThreadLocal has been set already
        LoggerContext lc = threadLocal.get();
        if (lc != null) {
            return lc;
        }

        try {
            // We first try to find the name of our
            // environment's LoggerContext
            ctx = JNDIUtil.getInitialContext();
            contextName = (String) JNDIUtil.lookupString(ctx, JNDI_CONTEXT_NAME);
        } catch (NamingException ne) {
            // We can't log here
        }

        if (contextName == null) {
            // We return the default context
            return defaultContext;
        } else {
            // Let's see if we already know such a context
            LoggerContext loggerContext = synchronizedContextMap.get(contextName);

            if (loggerContext == null) {
                // We have to create a new LoggerContext
                loggerContext = new LoggerContext();
                loggerContext.setName(contextName);
                synchronizedContextMap.put(contextName, loggerContext);
                URL url = findConfigFileURL(ctx, loggerContext);
                if (url != null) {
                    configureLoggerContextByURL(loggerContext, url);
                } else {
                    try {
                        new ContextInitializer(loggerContext).autoConfig();
                    } catch (JoranException je) {
                    }
                }
                // logback-292
                if (!StatusUtil.contextHasStatusListener(loggerContext))
                    StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
            }
            return loggerContext;
        }
    }
@Test
    public void defaultContext() {
        MockInitialContext mic = MockInitialContextFactory.getContext();
        mic.map.put(ClassicConstants.JNDI_CONTEXT_NAME, null);

        ContextJNDISelector selector = (ContextJNDISelector) ContextSelectorStaticBinder.getSingleton()
                .getContextSelector();
        Context context = selector.getLoggerContext();

        assertEquals("default", context.getName());
    }