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.LogLog; 23 import org.apache.log4j.helpers.OptionConverter; 24 25 54 public class LevelRangeFilter extends Filter { 55 56 59 boolean acceptOnMatch = false; 60 61 Level levelMin; 62 Level levelMax; 63 64 65 68 public 69 int decide(LoggingEvent event) { 70 if(this.levelMin != null) { 71 if (event.getLevel().isGreaterOrEqual(levelMin) == false) { 72 return Filter.DENY; 74 } 75 } 76 77 if(this.levelMax != null) { 78 if (event.getLevel().toInt() > levelMax.toInt()) { 79 return Filter.DENY; 84 } 85 } 86 87 if (acceptOnMatch) { 88 return Filter.ACCEPT; 91 } 92 else { 93 return Filter.NEUTRAL; 95 } 96 } 97 98 100 public 101 Level getLevelMax() { 102 return levelMax; 103 } 104 105 106 108 public 109 Level getLevelMin() { 110 return levelMin; 111 } 112 113 116 public 117 boolean getAcceptOnMatch() { 118 return acceptOnMatch; 119 } 120 121 124 public 125 void setLevelMax(Level levelMax) { 126 this.levelMax = levelMax; 127 } 128 129 132 public 133 void setLevelMin(Level levelMin) { 134 this.levelMin = levelMin; 135 } 136 137 140 public 141 void setAcceptOnMatch(boolean acceptOnMatch) { 142 this.acceptOnMatch = acceptOnMatch; 143 } 144 } 145 146 | Popular Tags |