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

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


    }

    @Test
    public void testConfig() {
        final LoggerContext ctx = Configurator.initialize("Test1", null, "target/test-classes/log4j2-mapfilter.xml");
        final Configuration config = ctx.getConfiguration();
        final Filter filter = config.getFilter();
        assertNotNull("No MapFilter", filter);
        assertTrue("Not a MapFilter", filter instanceof  MapFilter);
        final MapFilter mapFilter = (MapFilter) filter;
        assertFalse("Should not be And filter", mapFilter.isAnd());
        final Map<String, List<String>> map = mapFilter.getMap();
        assertNotNull("No Map", map);
        assertTrue("No elements in Map", map.size() != 0);
        assertTrue("Incorrect number of elements in Map", map.size() == 1);
        assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
        assertTrue("List does not contain 2 elements", map.get("eventId").size() == 2);
        final Logger logger = LogManager.getLogger(MapFilterTest.class);
        final Map<String, String> eventMap = new HashMap<String, String>();
        eventMap.put("eventId", "Login");
        logger.debug(new MapMessage(eventMap));
        final Map<String,Appender<?>> appenders = config.getAppenders();
        final Appender app = appenders.get("LIST");
        assertNotNull("No List appender", app);
        @SuppressWarnings("unchecked")
        final List<String> msgs = ((ListAppender<String>) app).getMessages();
        assertNotNull("No messages", msgs);
View Full Code Here


        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

        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()));
        System.clearProperty("targetDir");
    }
View Full Code Here

        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

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

    }

    @Test
    public void testConfig() {
        LoggerContext ctx = Configurator.initialize("Test1", null, "target/test-classes/log4j2-dynamicfilter.xml");
        Configuration config = ctx.getConfiguration();
        Filter filter = config.getFilter();
        assertNotNull("No DynamicThresholdFilter", filter);
        assertTrue("Not a DynamicThresholdFilter", filter instanceof DynamicThresholdFilter);
        DynamicThresholdFilter dynamic = (DynamicThresholdFilter) filter;
        String key = dynamic.getKey();
        assertNotNull("Key is null", key);
View Full Code Here

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

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

    @BeforeClass
    public static void setupClass() {

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

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

    }

    @Test
    public void testConfig() {
        LoggerContext ctx = Configurator.initialize("Test1", null, "target/test-classes/log4j2-mapfilter.xml");
        Configuration config = ctx.getConfiguration();
        Filter filter = config.getFilter();
        assertNotNull("No MapFilter", filter);
        assertTrue("Not a MapFilter", filter instanceof  MapFilter);
        MapFilter mapFilter = (MapFilter) filter;
        assertFalse("Should not be And filter", mapFilter.isAnd());
        Map<String, List<String>> map = mapFilter.getMap();
        assertNotNull("No Map", map == null);
        assertTrue("No elements in Map", map.size() != 0);
        assertTrue("Incorrect number of elements in Map", map.size() == 1);
        assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
        assertTrue("List does not contain 2 elements", map.get("eventId").size() == 2);
        Logger logger = LogManager.getLogger(MapFilterTest.class);
        Map<String, String> eventMap = new HashMap<String, String>();
        eventMap.put("eventId", "Login");
        logger.debug(new MapMessage(eventMap));
        Map<String,Appender> appenders = config.getAppenders();
        Appender app = appenders.get("LIST");
        assertNotNull("No List appender", app);
        List<String> msgs = ((ListAppender) app).getMessages();
        assertNotNull("No messages", msgs);
        assertTrue("No messages", msgs.size() > 0);
View Full Code Here

        file.setLastModified(newTime);
        Thread.sleep(6000);
        for (int i = 0; i < 17; ++i) {
            logger.debug("Reconfigure");
        }
        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.