public void deny() throws Exception { // set up appender Layout layout = new SimpleLayout(); Appender appender = new FileAppender(layout, DENY_FILE, false); // create LevelMatchFilter, set to deny matches LevelMatchFilter matchFilter = new LevelMatchFilter(); matchFilter.setAcceptOnMatch(false); // attach match filter to appender appender.addFilter(matchFilter); // set appender on root and set level to debug root.addAppender(appender); root.setLevel(Level.TRACE); Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL}; for (int x = 0; x < levelArray.length; x++) { // set the level to match matchFilter.setLevelToMatch(levelArray[x].toString()); common("pass " + x + "; filter set to deny only " + levelArray[x].toString() + " msgs"); } Transformer.transform(DENY_FILE, DENY_FILTERED, new LineNumberFilter()); assertTrue(Compare.compare(DENY_FILTERED, DENY_WITNESS)); }
public void accept() throws Exception { // set up appender Layout layout = new SimpleLayout(); Appender appender = new FileAppender(layout, ACCEPT_FILE, false); // create LevelMatchFilter LevelMatchFilter matchFilter = new LevelMatchFilter(); // attach match filter to appender appender.addFilter(matchFilter); // attach DenyAllFilter to end of filter chain to deny neutral // (non matching) messages appender.addFilter(new DenyAllFilter()); // set appender on root and set level to debug root.addAppender(appender); root.setLevel(Level.TRACE); Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL}; for (int x = 0; x < levelArray.length; x++) { // set the level to match matchFilter.setLevelToMatch(levelArray[x].toString()); common("pass " + x + "; filter set to accept only " + levelArray[x].toString() + " msgs"); } Transformer.transform(ACCEPT_FILE, ACCEPT_FILTERED, new LineNumberFilter()); assertTrue(Compare.compare(ACCEPT_FILTERED, ACCEPT_WITNESS)); }