Examples of LoggerContext


Examples of org.apache.logging.log4j.core.LoggerContext

        context.setInitParameter(Log4jContextListener.LOG4J_CONFIG, "target/test-classes/log4j2-config.xml");
        final Log4jContextListener listener = new Log4jContextListener();
        final ServletContextEvent event = new ServletContextEvent(context);
        listener.contextInitialized(event);
        LogManager.getLogger("org.apache.test.TestConfigurator");
        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
            CONFIG_NAME.equals(config.getName()));
        final Map<String, Appender<?>> map = config.getAppenders();
        assertTrue("No Appenders", map != null && map.size() > 0);
        assertTrue("Wrong configuration", map.containsKey("List"));
        listener.contextDestroyed(event);
        config = ctx.getConfiguration();
        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + " but found " +
            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

        context.setInitParameter(Log4jContextListener.LOG4J_CONFIG, "log4j2-config.xml");
        final Log4jContextListener listener = new Log4jContextListener();
        final ServletContextEvent event = new ServletContextEvent(context);
        listener.contextInitialized(event);
        LogManager.getLogger("org.apache.test.TestConfigurator");
        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
            CONFIG_NAME.equals(config.getName()));
        final Map<String, Appender<?>> map = config.getAppenders();
        assertTrue("No Appenders", map != null && map.size() > 0);
        assertTrue("Wrong configuration", map.containsKey("List"));
        listener.contextDestroyed(event);
        config = ctx.getConfiguration();
        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + " but found " +
            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

        context.setInitParameter(Log4jContextListener.LOG4J_CONTEXT_NAME, "-config");
        final Log4jContextListener listener = new Log4jContextListener();
        final ServletContextEvent event = new ServletContextEvent(context);
        listener.contextInitialized(event);
        LogManager.getLogger("org.apache.test.TestConfigurator");
        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
            CONFIG_NAME.equals(config.getName()));
        final Map<String, Appender<?>> map = config.getAppenders();
        assertTrue("No Appenders", map != null && map.size() > 0);
        assertTrue("Wrong configuration", map.containsKey("List"));
        listener.contextDestroyed(event);
        config = ctx.getConfiguration();
        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + " but found " +
            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    public static void tearDownClass() {
    }

    @After
    public void tearDown() {
        final LoggerContext ctx = (LoggerContext) org.apache.logging.log4j.LogManager.getContext();
        ctx.reconfigure();
        a1 = null;
        a2 = null;
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    @BeforeClass
    public static void setupClass() {
        appender.start();
        ConfigurationFactory.setConfigurationFactory(cf);
        final LoggerContext ctx = (LoggerContext) org.apache.logging.log4j.LogManager.getContext();
        ctx.reconfigure();
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    static ConfigurationFactory cf = new BasicConfigurationFactory();

    @BeforeClass
    public static void setupClass() {
        ConfigurationFactory.setConfigurationFactory(cf);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    @BeforeClass
    public static void setupClass() {
        StatusLogger.getLogger().setLevel(Level.OFF);
        ConfigurationFactory.setConfigurationFactory(cf);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    static ConfigurationFactory cf = new BasicConfigurationFactory();

    @BeforeClass
    public static void setupClass() {
        ConfigurationFactory.setConfigurationFactory(cf);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
    }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    @Override
    public LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext,
                                    URI configLocation) {
        if (currentContext) {
            final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get();
            if (ctx != null) {
                return ctx;
            }
            return getDefault();
        } else if (loader != null) {
            return locateContext(loader, configLocation);
        } else {
            if (getCallerClass != null) {
                try {
                    Class clazz = Class.class;
                    boolean next = false;
                    for (int index = 2; clazz != null; ++index) {
                        final Object[] params = new Object[] {index};
                        clazz = (Class) getCallerClass.invoke(null, params);
                        if (clazz == null) {
                            break;
                        }
                        if (clazz.getName().equals(fqcn)) {
                            next = true;
                            continue;
                        }
                        if (next) {
                            break;
                        }
                    }
                    if (clazz != null) {
                        return locateContext(clazz.getClassLoader(), configLocation);
                    }
                } catch (final Exception ex) {
                    // logger.debug("Unable to determine caller class via Sun Reflection", ex);
                }
            }

            if (securityManager != null) {
                final Class clazz = securityManager.getCaller(fqcn);
                if (clazz != null) {
                    final ClassLoader ldr = clazz.getClassLoader() != null ? clazz.getClassLoader() :
                        ClassLoader.getSystemClassLoader();
                    return locateContext(ldr, configLocation);
                }
            }

            final Throwable t = new Throwable();
            boolean next = false;
            String name = null;
            for (final StackTraceElement element : t.getStackTrace()) {
                if (element.getClassName().equals(fqcn)) {
                    next = true;
                    continue;
                }
                if (next) {
                    name = element.getClassName();
                    break;
                }
            }
            if (name != null) {
                try {
                    return locateContext(Loader.loadClass(name).getClassLoader(), configLocation);
                } catch (final ClassNotFoundException ex) {
                    //System.out.println("Could not load class " + name);
                }
            }
            final LoggerContext lc = ContextAnchor.THREAD_CONTEXT.get();
            if (lc != null) {
                return lc;
            }
            return getDefault();
        }
View Full Code Here

Examples of org.apache.logging.log4j.core.LoggerContext

    }

    @Override
    public void removeContext(final LoggerContext context) {
        for (final Map.Entry<String, AtomicReference<WeakReference<LoggerContext>>> entry : CONTEXT_MAP.entrySet()) {
            final LoggerContext ctx = entry.getValue().get().get();
            if (ctx == context) {
                CONTEXT_MAP.remove(entry.getKey());
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.