Java Code Examples for org.apache.logging.log4j.core.config.Configuration#getFilter()
The following examples show how to use
org.apache.logging.log4j.core.config.Configuration#getFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertiesConfigurationTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testPropertiesConfiguration() { final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); }
Example 2
Source File: PropertiesConfigurationRootLoggerOnlyTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testPropertiesConfiguration() { final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1); final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); }
Example 3
Source File: PropertiesConfigurationTrailingSpaceOnLevelTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testPropertiesConfiguration() { final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final Logger logger = LogManager.getLogger(getClass()); assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel()); logger.debug("Welcome to Log4j!"); }
Example 4
Source File: RollingFilePropertiesTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testPropertiesConfiguration() { final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); }
Example 5
Source File: DynamicThresholdFilterTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testConfig() { try (final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-dynamicfilter.xml")) { final Configuration config = ctx.getConfiguration(); final Filter filter = config.getFilter(); assertNotNull("No DynamicThresholdFilter", filter); assertTrue("Not a DynamicThresholdFilter", filter instanceof DynamicThresholdFilter); final DynamicThresholdFilter dynamic = (DynamicThresholdFilter) filter; final String key = dynamic.getKey(); assertNotNull("Key is null", key); assertEquals("Incorrect key value", "loginId", key); final Map<String, Level> map = dynamic.getLevelMap(); assertNotNull("Map is null", map); assertEquals("Incorrect number of map elements", 1, map.size()); } }
Example 6
Source File: MapFilterTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testConfig() { final Configuration config = context.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 IndexedReadOnlyStringMap map = mapFilter.getStringMap(); assertNotNull("No Map", map); assertFalse("No elements in Map", map.isEmpty()); assertEquals("Incorrect number of elements in Map", 1, map.size()); assertTrue("Map does not contain key eventId", map.containsKey("eventId")); assertEquals("List does not contain 2 elements", 2, map.<Collection<?>>getValue("eventId").size()); final Logger logger = LogManager.getLogger(MapFilterTest.class); final Map<String, String> eventMap = new HashMap<>(); eventMap.put("eventId", "Login"); logger.debug(new StringMapMessage(eventMap)); final ListAppender app = context.getListAppender("LIST"); final List<String> msgs = app.getMessages(); assertNotNull("No messages", msgs); assertFalse("No messages", msgs.isEmpty()); }
Example 7
Source File: ConfigurationAssemblerTest.java From pulsar with Apache License 2.0 | 5 votes |
private void validate(final Configuration config) { assertNotNull(config); assertNotNull(config.getName()); assertFalse(config.getName().isEmpty()); assertNotNull(config, "No configuration created"); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertEquals("Incorrect number of Appenders: " + appenders.size(), appenders.size(), 2); final PulsarAppender pulsarAppender = (PulsarAppender) appenders.get("Pulsar"); final GelfLayout gelfLayout = (GelfLayout) pulsarAppender.getLayout(); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertEquals("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size(), 2); final LoggerConfig rootLoggerConfig = loggers.get(""); assertEquals(Level.ERROR, rootLoggerConfig.getLevel()); assertFalse(rootLoggerConfig.isIncludeLocation()); final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j"); assertEquals(Level.DEBUG, loggerConfig.getLevel()); assertTrue(loggerConfig.isIncludeLocation()); final Filter filter = config.getFilter(); assertNotNull(filter, "No Filter"); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final List<CustomLevelConfig> customLevels = config.getCustomLevels(); assertNotNull(filter, "No CustomLevels"); assertEquals(1, customLevels.size()); final CustomLevelConfig customLevel = customLevels.get(0); assertEquals("Panic", customLevel.getLevelName()); assertEquals(17, customLevel.getIntLevel()); final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); }
Example 8
Source File: ConfigurationAssemblerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private void validate(final Configuration config) { assertNotNull(config); assertNotNull(config.getName()); assertFalse(config.getName().isEmpty()); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 2); final KafkaAppender kafkaAppender = (KafkaAppender) appenders.get("Kafka"); final GelfLayout gelfLayout = (GelfLayout) kafkaAppender.getLayout(); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); final LoggerConfig rootLoggerConfig = loggers.get(""); assertEquals(Level.ERROR, rootLoggerConfig.getLevel()); assertFalse(rootLoggerConfig.isIncludeLocation()); final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j"); assertEquals(Level.DEBUG, loggerConfig.getLevel()); assertTrue(loggerConfig.isIncludeLocation()); final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final List<CustomLevelConfig> customLevels = config.getCustomLevels(); assertNotNull("No CustomLevels", filter); assertEquals(1, customLevels.size()); final CustomLevelConfig customLevel = customLevels.get(0); assertEquals("Panic", customLevel.getLevelName()); assertEquals(17, customLevel.getIntLevel()); final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); }
Example 9
Source File: ConfigurationAssemblerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private void validate(final Configuration config) { assertNotNull(config); assertNotNull(config.getName()); assertFalse(config.getName().isEmpty()); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); final ConsoleAppender consoleAppender = (ConsoleAppender)appenders.get("Stdout"); final PatternLayout gelfLayout = (PatternLayout)consoleAppender.getLayout(); final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); final LoggerConfig rootLoggerConfig = loggers.get(""); assertEquals(Level.ERROR, rootLoggerConfig.getLevel()); assertFalse(rootLoggerConfig.isIncludeLocation()); final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j"); assertEquals(Level.DEBUG, loggerConfig.getLevel()); assertTrue(loggerConfig.isIncludeLocation()); final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); final List<CustomLevelConfig> customLevels = config.getCustomLevels(); assertNotNull("No CustomLevels", filter); assertEquals(1, customLevels.size()); final CustomLevelConfig customLevel = customLevels.get(0); assertEquals("Panic", customLevel.getLevelName()); assertEquals(17, customLevel.getIntLevel()); final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); }
Example 10
Source File: StructuredDataFilterTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testConfig() { final Configuration config = context.getConfiguration(); final Filter filter = config.getFilter(); assertNotNull("No StructuredDataFilter", filter); assertTrue("Not a StructuredDataFilter", filter instanceof StructuredDataFilter); final StructuredDataFilter sdFilter = (StructuredDataFilter) filter; assertFalse("Should not be And filter", sdFilter.isAnd()); final IndexedReadOnlyStringMap map = sdFilter.getStringMap(); assertNotNull("No Map", map); assertFalse("No elements in Map", map.isEmpty()); assertEquals("Incorrect number of elements in Map", 1, map.size()); assertTrue("Map does not contain key eventId", map.containsKey("eventId")); assertEquals("List does not contain 2 elements", 2, map.<Collection<?>>getValue("eventId").size()); }