View Javadoc
1 /* 2 * Created on 21.mar.2003 3 * 4 */ 5 package net.sf.panoptes.module.log4j; 6 7 8 import org.apache.commons.collections.Predicate; 9 import org.apache.log4j.Level; 10 11 12 /*** 13 * @author Dag Liodden 14 * 15 * version 0.1 16 * 17 */ 18 public class LogFilter implements Predicate { 19 20 private String prefix; 21 private String host; 22 private Level level; 23 24 public LogFilter(String host, String prefix, Level level) { 25 this.host = host; 26 this.prefix = prefix == null ? "" : prefix; 27 this.level = level; 28 if (this.level == null) level = Level.DEBUG; 29 } 30 31 public boolean evaluate(Object input) { 32 if (!(input instanceof LoggingEventInfo)) 33 throw new IllegalArgumentException("Can only evaluate LogginEventInfos, got " + input); 34 LoggingEventInfo e = (LoggingEventInfo) input; 35 try { 36 return ( 37 e.getHost().equals(host) 38 && e.getLoggingEvent().getLocationInformation().getClassName().startsWith(prefix) 39 && e.getLoggingEvent().getLevel().isGreaterOrEqual(level)); 40 } catch (Exception ex) { 41 ex.printStackTrace(); 42 return false; 43 } 44 } 45 /*** 46 * @return 47 */ 48 public String getHost() { 49 return host; 50 } 51 52 /*** 53 * @return 54 */ 55 public String getPrefix() { 56 return prefix; 57 } 58 59 60 /*** 61 * @return 62 */ 63 public Level getLevel() { 64 return level; 65 } 66 67 /*** 68 * @param level 69 */ 70 public void setLevel(Level level) { 71 this.level = level; 72 } 73 74 /*** 75 * @param string 76 */ 77 public void setPrefix(String string) { 78 prefix = string; 79 } 80 81 }

This page was automatically generated by Maven