use of org.apache.logging.log4j.core.filter.CompositeFilter in project logging-log4j2 by apache.
the class CustomLevelsWithFiltersTest method testConfiguration.
@Test
public void testConfiguration() {
final Configuration configuration = context.getConfiguration();
assertNotNull(configuration);
final FileAppender appender = configuration.getAppender("info");
assertNotNull(appender);
final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
assertNotNull(compFilter);
final Filter[] filters = compFilter.getFiltersArray();
assertNotNull(filters);
boolean foundLevel = false;
for (final Filter filter : filters) {
final ThresholdFilter tFilter = (ThresholdFilter) filter;
if (infom1Level.equals(tFilter.getLevel())) {
foundLevel = true;
break;
}
}
Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
}
use of org.apache.logging.log4j.core.filter.CompositeFilter in project logging-log4j2 by apache.
the class TestConfigurator method testNoFilters.
@Test
public void testNoFilters() throws Exception {
ctx = Configurator.initialize("Test1", "bad/log4j-nofilter.xml");
LogManager.getLogger("org.apache.test.TestConfigurator");
final Configuration config = ctx.getConfiguration();
assertNotNull(config, "No configuration");
assertEquals("XMLConfigTest", config.getName(), "Unexpected Configuration");
final LoggerConfig lcfg = config.getLoggerConfig("org.apache.logging.log4j.test1");
assertNotNull(lcfg, "No Logger");
final Filter filter = lcfg.getFilter();
assertNotNull(filter, "No Filter");
assertThat(filter, instanceOf(CompositeFilter.class));
assertTrue(((CompositeFilter) filter).isEmpty(), "Unexpected filters");
}
use of org.apache.logging.log4j.core.filter.CompositeFilter in project SpongeCommon by SpongePowered.
the class MixinLoggerInjector method captureLogger.
public static Queue<String> captureLogger() {
if (!MixinEnvironment.getDefaultEnvironment().getOption(MixinEnvironment.Option.DEBUG_VERBOSE)) {
throw new IllegalStateException("Mixin capture will not function appropriately unless -Dmixin.debug.verbose is enabled");
}
final Logger mixinLogger = (Logger) LogManager.getLogger("mixin");
final CompositeFilter messageFilter = CompositeFilter.createFilters(new Filter[] { // regex patterns
MixinLoggerInjector.pattern(".*for final field [^@]+@Mutable.*"), // MixinLoggerInjector.pattern("^NESTING not supported.*"), // todo: if we need to
new DenyAllFilter() });
final CaptureAppender appender = CaptureAppender.builder().setName("IntegrationTest-Capture").setFilter(messageFilter).build();
appender.start();
mixinLogger.addAppender(appender);
return appender.messages();
}
use of org.apache.logging.log4j.core.filter.CompositeFilter in project logging-log4j2 by apache.
the class CustomLevelsWithFiltersTest method testConfiguration.
@Test
public void testConfiguration(final Configuration configuration, @Named("info") final FileAppender appender) {
assertNotNull(configuration);
assertNotNull(appender);
final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
assertNotNull(compFilter);
final Filter[] filters = compFilter.getFiltersArray();
assertNotNull(filters);
boolean foundLevel = false;
for (final Filter filter : filters) {
final ThresholdFilter tFilter = (ThresholdFilter) filter;
if (infom1Level.equals(tFilter.getLevel())) {
foundLevel = true;
break;
}
}
assertTrue(foundLevel, "Level not found: " + infom1Level);
}
use of org.apache.logging.log4j.core.filter.CompositeFilter in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testConsoleAppenderLevelRangeFilter.
@Test
public void testConsoleAppenderLevelRangeFilter() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3326.properties")) {
final Configuration configuration = loggerContext.getConfiguration();
assertNotNull(configuration);
final Appender appender = configuration.getAppender("CUSTOM");
assertNotNull(appender);
final Filterable filterable = (Filterable) appender;
final CompositeFilter filter = (CompositeFilter) filterable.getFilter();
final org.apache.logging.log4j.core.Filter[] filters = filter.getFiltersArray();
final LevelRangeFilter customFilterReal = (LevelRangeFilter) ((FilterWrapper) ((FilterAdapter) filters[0]).getFilter()).getFilter();
assertEquals(Level.ALL, customFilterReal.getMinLevel());
final LevelRangeFilter defaultFilter = (LevelRangeFilter) ((FilterWrapper) ((FilterAdapter) filters[1]).getFilter()).getFilter();
assertEquals(Level.TRACE, defaultFilter.getMinLevel());
}
}
Aggregations