1 22 package org.jboss.logging.appender; 23 24 import java.util.HashMap ; 25 import java.util.regex.Matcher ; 26 import java.util.regex.Pattern ; 27 28 import org.apache.log4j.spi.LoggingEvent; 29 import org.apache.log4j.spi.TriggeringEventEvaluator; 30 31 37 public class RegexEventEvaluator implements TriggeringEventEvaluator 38 { 39 40 private HashMap regexMap = new HashMap (); 41 42 51 public boolean isTriggeringEvent(LoggingEvent event) 52 { 53 String regex = (String ) event.getMDC("RegexEventEvaluator"); 54 boolean isTriggeringEvent = false; 55 if( regex != null ) 56 { 57 Pattern re = (Pattern ) regexMap.get(regex); 59 if( re == null ) 60 { 61 re = Pattern.compile(regex); 62 regexMap.put(regex, re); 63 } 64 65 if( re != null ) 66 { 67 String msg = event.getRenderedMessage(); 68 if( msg != null ) 69 { 70 Matcher m = re.matcher(msg); 71 isTriggeringEvent = m.matches(); 72 } 73 } 74 } 75 return isTriggeringEvent; 76 } 77 } 78 79 | Popular Tags |