use of org.apache.log4j.bridge.FilterAdapter in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testConsoleAppenderFilter.
@Test
public void testConsoleAppenderFilter() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3247.properties")) {
// LOG4J2-3281 PropertiesConfiguration.buildAppender not adding filters to appender
final Configuration configuration = loggerContext.getConfiguration();
assertNotNull(configuration);
final Appender appender = configuration.getAppender("CONSOLE");
assertNotNull(appender);
final Filterable filterable = (Filterable) appender;
final FilterAdapter filter = (FilterAdapter) filterable.getFilter();
assertNotNull(filter);
assertTrue(filter.getFilter() instanceof NeutralFilterFixture);
}
}
use of org.apache.log4j.bridge.FilterAdapter in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testCustomAppenderFilter.
@Test
public void testCustomAppenderFilter() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3281.properties")) {
// LOG4J2-3281 PropertiesConfiguration.buildAppender not adding filters to appender
final Configuration configuration = loggerContext.getConfiguration();
assertNotNull(configuration);
final Appender appender = configuration.getAppender("CUSTOM");
assertNotNull(appender);
final Filterable filterable = (Filterable) appender;
final FilterAdapter filter = (FilterAdapter) filterable.getFilter();
assertNotNull(filter);
assertTrue(filter.getFilter() instanceof NeutralFilterFixture);
}
}
use of org.apache.log4j.bridge.FilterAdapter in project logging-log4j2 by apache.
the class AbstractBuilder method buildFilters.
protected org.apache.logging.log4j.core.Filter buildFilters(final String level, final Filter filter) {
if (level != null && filter != null) {
final List<org.apache.logging.log4j.core.Filter> filterList = new ArrayList<>();
final org.apache.logging.log4j.core.Filter thresholdFilter = ThresholdFilter.createFilter(OptionConverter.convertLevel(level, Level.TRACE), org.apache.logging.log4j.core.Filter.Result.NEUTRAL, org.apache.logging.log4j.core.Filter.Result.DENY);
filterList.add(thresholdFilter);
Filter f = filter;
while (f != null) {
if (filter instanceof FilterWrapper) {
filterList.add(((FilterWrapper) f).getFilter());
} else {
filterList.add(new FilterAdapter(f));
}
f = f.getNext();
}
return CompositeFilter.createFilters(filterList.toArray(org.apache.logging.log4j.core.Filter.EMPTY_ARRAY));
} else if (level != null) {
return ThresholdFilter.createFilter(OptionConverter.convertLevel(level, Level.TRACE), org.apache.logging.log4j.core.Filter.Result.NEUTRAL, org.apache.logging.log4j.core.Filter.Result.DENY);
} else if (filter != null) {
if (filter instanceof FilterWrapper) {
return ((FilterWrapper) filter).getFilter();
} else {
return new FilterAdapter(filter);
}
}
return null;
}
use of org.apache.log4j.bridge.FilterAdapter 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