Package org.apache.logging.log4j.core.config

Examples of org.apache.logging.log4j.core.config.Configuration


            status = Status.STOPPING;
            if (shutdownThread != null) {
                Runtime.getRuntime().removeShutdownHook(shutdownThread);
                shutdownThread = null;
            }
            final Configuration prev = config;
            config = new NullConfiguration();
            updateLoggers();
            prev.stop();
            externalContext = null;
            LogManager.getFactory().removeContext(this);
            status = Status.STOPPED;
        } finally {
            configLock.unlock();
View Full Code Here


     */
    private synchronized Configuration setConfiguration(final Configuration config) {
        if (config == null) {
            throw new NullPointerException("No Configuration was provided");
        }
        final Configuration prev = this.config;
        config.addListener(this);
        final Map<String, String> map = new HashMap<String, String>();
        map.put("hostName", NetUtils.getLocalHostname());
        map.put("contextName", name);
        config.addComponent(Configuration.CONTEXT_PROPERTIES, map);
        config.start();
        this.config = config;
        updateLoggers();
        if (prev != null) {
            prev.removeListener(this);
            prev.stop();
        }

        // notify listeners
        final PropertyChangeEvent evt = new PropertyChangeEvent(this, PROPERTY_CONFIG, prev, config);
        for (final PropertyChangeListener listener : propertyChangeListeners) {
View Full Code Here

    /**
     * Reconfigure the context.
     */
    public synchronized void reconfigure() {
        LOGGER.debug("Reconfiguration started for context " + name);
        final Configuration instance = ConfigurationFactory.getInstance().getConfiguration(name, configLocation);
        setConfiguration(instance);
        /*
         * instance.start(); Configuration old = setConfiguration(instance);
         * updateLoggers(); if (old != null) { old.stop(); }
         */
 
View Full Code Here

     * @param reconfigurable The Configuration that can be reconfigured.
     */
    @Override
    public synchronized void onChange(final Reconfigurable reconfigurable) {
        LOGGER.debug("Reconfiguration started for context " + name);
        final Configuration config = reconfigurable.reconfigure();
        if (config != null) {
            setConfiguration(config);
            LOGGER.debug("Reconfiguration completed");
        } else {
            LOGGER.debug("Reconfiguration failed");
View Full Code Here

        logger.entry();
        List<LogEvent> events = app.getEvents();
        assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
        app.clear();
        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        final Configuration config = ctx.getConfiguration();
        final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
        /* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
           LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
        */
        loggerConfig.setLevel(Level.DEBUG);
        ctx.updateLoggers()// This causes all Loggers to refetch information from their LoggerConfig.
View Full Code Here

        try {
            initializer.initialize();
            initializer.setLoggerContext();
            LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get();
            assertNotNull("No LoggerContext", ctx);
            Configuration config = ctx.getConfiguration();
            assertNotNull("No Configuration", config);
            StrSubstitutor substitutor = config.getStrSubstitutor();
            assertNotNull("No Interpolator", substitutor);
            String value = substitutor.replace("${web:initParam.TestParam}");
            assertNotNull("No value for TestParam", value);
            assertTrue("Incorrect value for TestParam: " + value, "ParamValue".equals(value));
            value = substitutor.replace("${web:attr.TestAttr}");
View Full Code Here

    private static int[] values = new int[RAND_SIZE];

    @BeforeClass
    public static void setupClass() {

        final Configuration config = ((LoggerContext)LogManager.getContext()).getConfiguration();
        if (!DefaultConfiguration.DEFAULT_NAME.equals(config.getName())) {
            System.out.println("Configuration was " + config.getName());
            ((LoggerContext)LogManager.getContext()).start(new DefaultConfiguration());
        }

        for (int i=0; i < WARMUP; ++i) {
            overhead();
View Full Code Here

        ctx = (LoggerContext) LogManager.getContext(false);
    }

    @Test
    public void testReconfiguration() throws Exception {
        final Configuration cfg = ctx.getConfiguration();
        assertNotNull("No configuration", cfg);
        assertTrue("Not set to default configuration", cfg instanceof DefaultConfiguration);
        final File file = new File(CONFIG);
        LoggerContext loggerContext = (LoggerContext) LogManager.getContext(null, false, file.toURI());
        assertNotNull("No Logger Context", loggerContext);
        final Configuration newConfig = loggerContext.getConfiguration();
        assertTrue("Configuration not reset", cfg != newConfig);
        assertTrue("Reconfiguration failed", newConfig instanceof XMLConfiguration);
        ctx = (LoggerContext) LogManager.getContext(false);
        final Configuration sameConfig = ctx.getConfiguration();
        assertTrue("Configuration should not have been reset", newConfig == sameConfig);
    }
View Full Code Here

    @BeforeClass
    public static void setupClass() {
        deleteDir();
        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final Configuration config = ctx.getConfiguration();
    }
View Full Code Here

        file.setLastModified(newTime);
        Thread.sleep(6000);
        for (int i = 0; i < 17; ++i) {
            logger.debug("Reconfigure");
        }
        final Configuration cfg = ctx.getConfiguration();
        assertNotNull("No configuration", cfg);
        assertTrue("Reconfiguration failed", cfg != config);
    }
View Full Code Here

TOP

Related Classes of org.apache.logging.log4j.core.config.Configuration

Copyright © 2018 www.massapicom. 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.