use of ch.qos.logback.core.filter.Filter in project sling by apache.
the class ITFilterSupport method filterUsingWildcard.
@Test
public void filterUsingWildcard() throws Exception {
TestAppender ta1 = registerAppender("filterUsingWildcard1", "app1");
TestAppender ta2 = registerAppender("filterUsingWildcard2", "app2");
//Set additivity to false to prevent other appender like CONSOLE from
//interfering
org.slf4j.Logger baz1 = LoggerFactory.getLogger("filterUsingWildcard1.foo.baz");
((ch.qos.logback.classic.Logger) baz1).setAdditive(false);
org.slf4j.Logger baz2 = LoggerFactory.getLogger("filterUsingWildcard2.foo.baz");
((ch.qos.logback.classic.Logger) baz2).setAdditive(false);
final List<String> msgs = new ArrayList<String>();
Filter stf = new Filter<ILoggingEvent>() {
@Override
public FilterReply decide(ILoggingEvent event) {
msgs.add(event.getMessage());
return FilterReply.NEUTRAL;
}
};
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("appenders", "*");
ServiceRegistration sr = bundleContext.registerService(Filter.class.getName(), stf, props);
delay();
baz1.info("baz1-1");
baz2.info("baz2-1");
assertEquals(2, msgs.size());
}
use of ch.qos.logback.core.filter.Filter in project sling by apache.
the class ITFilterSupport method testNormalFilter.
@Test
public void testNormalFilter() {
TestAppender ta = registerAppender("filter", "TestAppender");
org.slf4j.Logger bar = LoggerFactory.getLogger("filter.foo.bar");
assertTrue(bar.isDebugEnabled());
bar.debug("Test");
assertEquals(1, ta.events.size());
SimpleFilter stf = new SimpleFilter();
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("appenders", "TestAppender");
ServiceRegistration sr = bundleContext.registerService(Filter.class.getName(), stf, props);
delay();
assertNotNull("Filter should have context set", stf.getContext());
assertTrue("Filter should be started", stf.isStarted());
ta.events.clear();
//A filter attached to an appender cannot influence isXXXEnabled call
assertTrue(bar.isDebugEnabled());
//No events should be logged as filter would have rejected that
bar.debug("Test");
assertTrue(ta.events.isEmpty());
//Now unregister and earlier asserts should work
sr.unregister();
delay();
ta.events.clear();
assertTrue(bar.isDebugEnabled());
bar.debug("Test");
assertEquals(1, ta.events.size());
}
Aggregations