[logback-dev] svn commit: r851 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/tomcat logback-classic/src/main/java/ch/qos/logback/classic logback-classic/src/main/java/ch/qos/logback/classic/spi logback-classic/src/main/java/ch/qos/logback/classic/turbo logback-classic/src/test/java/ch/qos/logback/classic/turbo logback-core/src/main/java/ch/qos/logback/core logback-core/src/main/java/ch/qos/logback/core/filter logback-core/src/main/java/ch/qos/logback/core/spi
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Nov 2 14:55:45 CET 2006
Author: seb
Date: Thu Nov 2 14:55:44 2006
New Revision: 851
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/FilterReply.java
Modified:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachable.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachableImpl.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/NOPTurboFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
Log:
Added an enumeration to group the possible replies that filter components can return.
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java Thu Nov 2 14:55:44 2006
@@ -19,6 +19,7 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreGlobal;
import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.spi.AppenderAttachable;
import ch.qos.logback.core.spi.AppenderAttachableImpl;
@@ -211,7 +212,7 @@
fai.clearAllFilters();
}
- public int getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(Object event) {
return fai.getFilterChainDecision(event);
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java Thu Nov 2 14:55:44 2006
@@ -21,7 +21,7 @@
import ch.qos.logback.classic.spi.LoggerRemoteView;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.Appender;
-import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
import ch.qos.logback.core.spi.AppenderAttachable;
import ch.qos.logback.core.spi.AppenderAttachableImpl;
@@ -407,13 +407,13 @@
final void filterAndLog(final Marker marker, final Level level, final String msg, final Object[] params,
final Throwable t) {
- final int decision = loggerContext.getTurboFilterChainDecision(marker, this, Level.DEBUG, msg, params, t);
+ final FilterReply decision = loggerContext.getTurboFilterChainDecision(marker, this, Level.DEBUG, msg, params, t);
- if(decision == Filter.NEUTRAL) {
+ if(decision == FilterReply.NEUTRAL) {
if(effectiveLevelInt > level.levelInt) {
return;
}
- } else if (decision == Filter.DENY) {
+ } else if (decision == FilterReply.DENY) {
return;
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java Thu Nov 2 14:55:44 2006
@@ -16,13 +16,13 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.Marker;
-import ch.qos.logback.classic.turbo.TurboFilter;
+import ch.qos.logback.classic.spi.LoggerContextRemoteView;
import ch.qos.logback.classic.spi.TurboFilterAttachable;
import ch.qos.logback.classic.spi.TurboFilterAttachableImpl;
-import ch.qos.logback.classic.spi.LoggerContextRemoteView;
+import ch.qos.logback.classic.turbo.TurboFilter;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.CoreGlobal;
-import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
import ch.qos.logback.core.status.ErrorStatus;
/**
@@ -184,11 +184,11 @@
cfai = null;
}
- final public int getTurboFilterChainDecision(final Marker marker,
+ final public FilterReply getTurboFilterChainDecision(final Marker marker,
final Logger logger, final Level level, final String format, final Object[] params,
final Throwable t) {
if (cfai == null) {
- return Filter.NEUTRAL;
+ return FilterReply.NEUTRAL;
}
return cfai
.getTurboFilterChainDecision(marker, logger, level, format, params, t);
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachable.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachable.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachable.java Thu Nov 2 14:55:44 2006
@@ -5,6 +5,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.turbo.TurboFilter;
+import ch.qos.logback.core.filter.FilterReply;
/**
* Interface for attaching ClassicFilter instances to objects.
@@ -30,7 +31,7 @@
* ACCEPT or DENY, then that value is returned. If all of the filters return
* NEUTRAL, then NEUTRAL is returned.
*/
- public int getTurboFilterChainDecision(Marker marker, Logger logger,
+ public FilterReply getTurboFilterChainDecision(Marker marker, Logger logger,
Level level, String format, Object[] params, Throwable t);
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachableImpl.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachableImpl.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterAttachableImpl.java Thu Nov 2 14:55:44 2006
@@ -14,7 +14,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.turbo.TurboFilter;
-import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
/**
* Implementation of ClassicFilterAttachable.
@@ -66,22 +66,23 @@
* ACCEPT or DENY, then that value is returned. If all of the filters return
* NEUTRAL, then NEUTRAL is returned.
*/
- public final int getTurboFilterChainDecision(final Marker marker, final Logger logger,
+ public final FilterReply getTurboFilterChainDecision(final Marker marker, final Logger logger,
final Level level, final String format, final Object[] params, final Throwable t) {
TurboFilter f = headFilter;
+
while (f != null) {
switch (f.decide(marker, logger, level, format, params, t)) {
- case Filter.DENY:
- return Filter.DENY;
+ case DENY:
+ return FilterReply.DENY;
- case Filter.ACCEPT:
- return Filter.ACCEPT;
+ case ACCEPT:
+ return FilterReply.ACCEPT;
- case Filter.NEUTRAL:
+ case NEUTRAL:
f = f.getNext();
}
}
- return Filter.NEUTRAL;
+ return FilterReply.NEUTRAL;
}
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java Thu Nov 2 14:55:44 2006
@@ -9,7 +9,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.MDC;
-import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
/**
* This class allows output of debug level events to a certain list of users.
@@ -27,22 +27,22 @@
List<String> userList = new ArrayList<String>();
@Override
- public int decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
+ public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
if (!level.equals(Level.DEBUG)) {
- return Filter.NEUTRAL;
+ return FilterReply.NEUTRAL;
}
String user = MDC.get(ClassicGlobal.USER_MDC_KEY);
if (user != null && userList.contains(user)) {
- return Filter.ACCEPT;
+ return FilterReply.ACCEPT;
}
- return Filter.NEUTRAL;
+ return FilterReply.NEUTRAL;
}
public void addUser(String user) {
- System.out.println("******* ADD USER CALLED");
userList.add(user);
}
+ //test in BasicJoranTest only, to be removed asap.
public List<String> getUsers() {
return userList;
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java Thu Nov 2 14:55:44 2006
@@ -5,6 +5,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
@@ -38,7 +39,7 @@
* @param t
* @return
*/
- public abstract int decide(Marker marker, Logger logger,
+ public abstract FilterReply decide(Marker marker, Logger logger,
Level level, String format, Object[] params, Throwable t);
public void start() {
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/NOPTurboFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/NOPTurboFilter.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/NOPTurboFilter.java Thu Nov 2 14:55:44 2006
@@ -4,16 +4,15 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.turbo.TurboFilter;
-import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
public class NOPTurboFilter extends TurboFilter {
@Override
- public int decide(final Marker marker, final Logger logger, final Level level, final String format,
+ public FilterReply decide(final Marker marker, final Logger logger, final Level level, final String format,
final Object[] params, final Throwable t) {
- return Filter.NEUTRAL;
+ return FilterReply.NEUTRAL;
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java Thu Nov 2 14:55:44 2006
@@ -10,6 +10,7 @@
package ch.qos.logback.core;
import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.FilterAttachable;
import ch.qos.logback.core.spi.FilterAttachableImpl;
@@ -62,7 +63,7 @@
return;
}
- if (getFilterChainDecision(eventObject) == Filter.DENY) {
+ if (getFilterChainDecision(eventObject) == FilterReply.DENY) {
return;
}
@@ -111,7 +112,7 @@
fai.clearAllFilters();
}
- public int getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(Object event) {
return fai.getFilterChainDecision(event);
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java Thu Nov 2 14:55:44 2006
@@ -21,26 +21,26 @@
public abstract class AbstractEvalutatorFilter extends Filter {
- protected int onMatch = NEUTRAL;
- protected int onMismatch = NEUTRAL;
+ protected FilterReply onMatch = FilterReply.NEUTRAL;
+ protected FilterReply onMismatch = FilterReply.NEUTRAL;
final public void setOnMatch(String action) {
if ("NEUTRAL".equals(action)) {
- onMatch = NEUTRAL;
+ onMatch = FilterReply.NEUTRAL;
} else if ("ACCEPT".equals(action)) {
- onMatch = ACCEPT;
+ onMatch = FilterReply.ACCEPT;
} else if ("DENY".equals(action)) {
- onMatch = DENY;
+ onMatch = FilterReply.DENY;
}
}
final public void setOnMismatch(String action) {
if ("NEUTRAL".equals(action)) {
- onMismatch = NEUTRAL;
+ onMismatch = FilterReply.NEUTRAL;
} else if ("ACCEPT".equals(action)) {
- onMismatch = ACCEPT;
+ onMismatch = FilterReply.ACCEPT;
} else if ("DENY".equals(action)) {
- onMismatch = DENY;
+ onMismatch = FilterReply.DENY;
}
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java Thu Nov 2 14:55:44 2006
@@ -25,11 +25,11 @@
this.evaluator = evaluator;
}
- public int decide(Object event) {
+ public FilterReply decide(Object event) {
// let us not throw an exception
// see also bug #17.
if(!isStarted()) {
- return NEUTRAL;
+ return FilterReply.NEUTRAL;
}
try {
if (evaluator.evaluate(event)) {
@@ -39,7 +39,7 @@
}
} catch (EvaluationException e) {
addError("Evaluator "+evaluator.getName()+" threw an exception", e);
- return NEUTRAL;
+ return FilterReply.NEUTRAL;
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java Thu Nov 2 14:55:44 2006
@@ -13,7 +13,7 @@
* linear chain. The {@link #decide decide(Object)} method of each filter is
* called sequentially, in the order of their addition to the chain.
* <p>
- * The decide() method must return one of the integer constants {@link #DENY},
+ * The decide() method must return one of the FilterReplies {@link #DENY},
* {@link #NEUTRAL} or {@link #ACCEPT}.
* <p>
* If the value DENY is returned, then the log event is dropped immediately
@@ -30,7 +30,7 @@
* consulting the remaining filters.
*
* <p>
- * The philosophy of LOGBack filters are largely inspired from Linux ipchains.
+ * The philosophy of logback filters are largely inspired from Linux ipchains.
*
* @author Ceki Gülcü
*/
@@ -40,19 +40,19 @@
* The event must be dropped immediately without consulting with the remaining
* filters, if any, in the chain.
*/
- public static final int DENY = -1;
+ //public static final int DENY = -1;
/**
* This filter is neutral with respect to the event. The remaining filters, if
* any, should be consulted for a final decision.
*/
- public static final int NEUTRAL = 0;
+ //public static final int NEUTRAL = 0;
/**
* The event must be logged immediately without consulting with the remaining
* filters, if any, in the chain.
*/
- public static final int ACCEPT = 1;
+ //public static final int ACCEPT = 1;
/**
* Points to the next filter in the filter chain.
@@ -85,7 +85,7 @@
* @param event
* The event to decide upon.
*/
- public abstract int decide(Object event);
+ public abstract FilterReply decide(Object event);
/**
* Set the next filter pointer.
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/FilterReply.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/FilterReply.java Thu Nov 2 14:55:44 2006
@@ -0,0 +1,20 @@
+package ch.qos.logback.core.filter;
+
+/**
+ *
+ * This enum represents the possible replies that a filtering component
+ * in logback can return. It is used by implementations of both
+ * {@link ch.qos.logback.core.filter.Filter} and
+ * {@link ch.qos.logback.classic.turbo.TurboFilter} abstract classes.
+ *
+ * Based on the order that the FilterReply values are declared,
+ * FilterReply.ACCEPT.compareTo(FilterReply.DENY) will return
+ * a positive value.
+ *
+ * @author Sébastien Pennec
+ */
+public enum FilterReply {
+ DENY,
+ NEUTRAL,
+ ACCEPT;
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java Thu Nov 2 14:55:44 2006
@@ -10,6 +10,7 @@
package ch.qos.logback.core.spi;
import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
/**
* Interface for attaching filters to objects.
@@ -34,5 +35,5 @@
* ACCEPT or DENY, then that value is returned. If all of the filters return
* NEUTRAL, then NEUTRAL is returned.
*/
- public int getFilterChainDecision(Object event);
+ public FilterReply getFilterChainDecision(Object event);
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java Thu Nov 2 14:55:44 2006
@@ -10,6 +10,7 @@
package ch.qos.logback.core.spi;
import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.FilterReply;
/**
* Implementation of FilterAttachable.
@@ -61,21 +62,21 @@
* ACCEPT or DENY, then that value is returned. If all of the filters return
* NEUTRAL, then NEUTRAL is returned.
*/
- public int getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(Object event) {
Filter f = headFilter;
while (f != null) {
switch (f.decide(event)) {
- case Filter.DENY:
- return Filter.DENY;
+ case DENY:
+ return FilterReply.DENY;
- case Filter.ACCEPT:
- return Filter.ACCEPT;
+ case ACCEPT:
+ return FilterReply.ACCEPT;
- case Filter.NEUTRAL:
+ case NEUTRAL:
f = f.getNext();
}
}
- return Filter.NEUTRAL;
+ return FilterReply.NEUTRAL;
}
}
More information about the logback-dev
mailing list