1 16 17 package org.apache.log4j.varia; 18 19 import org.apache.log4j.Level; 20 import org.apache.log4j.spi.Filter; 21 import org.apache.log4j.spi.LoggingEvent; 22 import org.apache.log4j.helpers.OptionConverter; 23 24 39 public class LevelMatchFilter extends Filter { 40 41 44 boolean acceptOnMatch = true; 45 46 48 Level levelToMatch; 49 50 51 public 52 void setLevelToMatch(String level) { 53 levelToMatch = OptionConverter.toLevel(level, null); 54 } 55 56 public 57 String getLevelToMatch() { 58 return levelToMatch == null ? null : levelToMatch.toString(); 59 } 60 61 public 62 void setAcceptOnMatch(boolean acceptOnMatch) { 63 this.acceptOnMatch = acceptOnMatch; 64 } 65 66 public 67 boolean getAcceptOnMatch() { 68 return acceptOnMatch; 69 } 70 71 72 83 public 84 int decide(LoggingEvent event) { 85 if(this.levelToMatch == null) { 86 return Filter.NEUTRAL; 87 } 88 89 boolean matchOccured = false; 90 if(this.levelToMatch.equals(event.getLevel())) { 91 matchOccured = true; 92 } 93 94 if(matchOccured) { 95 if(this.acceptOnMatch) 96 return Filter.ACCEPT; 97 else 98 return Filter.DENY; 99 } else { 100 return Filter.NEUTRAL; 101 } 102 } 103 } 104 | Popular Tags |