[logback-dev] svn commit: r779 - in logback/trunk/logback-core/src/main/java/ch/qos/logback/core: filter joran/action util
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Wed Oct 25 23:33:57 CEST 2006
Author: ceki
Date: Wed Oct 25 23:33:56 2006
New Revision: 779
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/EvaluatorFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java
Log:
- trying to make an MDC based filtering work
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 Wed Oct 25 23:33:56 2006
@@ -24,6 +24,7 @@
int onMatch = NEUTRAL;
int onMismatch = NEUTRAL;
+
public void setOnMatch(String action) {
if ("NEUTRAL".equals(action)) {
onMatch = NEUTRAL;
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 Wed Oct 25 23:33:56 2006
@@ -7,8 +7,20 @@
EventEvaluator evaluator;
+ public EvaluatorFilter() {
+ }
-
+
+ public void setX(String action) {
+ if ("NEUTRAL".equals(action)) {
+ onMatch = NEUTRAL;
+ } else if ("ACCEPT".equals(action)) {
+ onMatch = ACCEPT;
+ } else if ("DENY".equals(action)) {
+ onMatch = DENY;
+ }
+ }
+
public void start() {
if(evaluator != null) {
super.start();
@@ -21,12 +33,17 @@
return evaluator;
}
+
public void setEvaluator(EventEvaluator evaluator) {
this.evaluator = evaluator;
}
public int decide(Object event) {
-
+ // let us not throw an exception
+ // see also bug #17.
+ if(!isStarted()) {
+ return NEUTRAL;
+ }
try {
if (evaluator.evaluate(event)) {
return onMatch;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java Wed Oct 25 23:33:56 2006
@@ -45,7 +45,7 @@
public boolean isApplicable(
Pattern pattern, Attributes attributes, InterpretationContext ec) {
- //LogLog.debug("in NestComponentIA.isApplicable <" + pattern + ">");
+ //System.out.println("in NestComponentIA.isApplicable <" + pattern + ">");
String nestedElementTagName = pattern.peekLast();
// calling ec.peekObject with an empty stack will throw an exception
@@ -55,7 +55,8 @@
Object o = ec.peekObject();
PropertySetter parentBean = new PropertySetter(o);
-
+ parentBean.setContext(context);
+
int containmentType = parentBean.canContainComponent(nestedElementTagName);
switch (containmentType) {
@@ -66,6 +67,7 @@
// we only push action data if NestComponentIA is applicable
case PropertySetter.AS_COLLECTION:
case PropertySetter.AS_COMPONENT:
+ addInfo("is dmmed applicable for "+pattern);
ImplicitActionData ad = new ImplicitActionData(parentBean, containmentType);
actionDataStack.push(ad);
@@ -108,7 +110,7 @@
((ContextAware) actionData.nestedComponent).setContext(this.context);
}
//getLogger().debug(
- // "Pushing component <{}> on top of the object stack.", localName);
+ addInfo("Pushing component <"+localName+"> on top of the object stack.");
ec.pushObject(actionData.nestedComponent);
} catch (Exception oops) {
actionData.inError = true;
@@ -151,9 +153,8 @@
// Now let us attach the component
switch (actionData.containmentType) {
case PropertySetter.AS_COMPONENT:
- //getLogger().debug(
- //"Setting [{}] to parent of type [{}]", tagName,
- //actionData.parentBean.getObjClass());
+ //addInfo("Setting ["+tagName+"}] to parent of type ["+actionData.parentBean.getObjClass()+"]");
+
actionData.parentBean.setComponent(
tagName, actionData.nestedComponent);
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java Wed Oct 25 23:33:56 2006
@@ -42,7 +42,7 @@
public boolean isApplicable(
Pattern pattern, Attributes attributes, InterpretationContext ec) {
- //LogLog.debug("in NestComponentIA.isApplicable <" + pattern + ">");
+ //System.out.println("in NestedSimplePropertyIA.isApplicable <" + pattern + ">");
String nestedElementTagName = pattern.peekLast();
// no point in attempting if there is no parent object
@@ -52,7 +52,8 @@
Object o = ec.peekObject();
PropertySetter parentBean = new PropertySetter(o);
-
+ parentBean.setContext(context);
+
int containmentType = parentBean.canContainComponent(nestedElementTagName);
switch (containmentType) {
@@ -65,7 +66,7 @@
ImplicitActionData ad = new ImplicitActionData(parentBean, containmentType);
ad.propertyName = nestedElementTagName;
actionDataStack.push(ad);
- // System.out.println("NestedSimplePropertyIA deemed applicable for " +pattern);
+ //System.out.println("in NestedSimplePropertyIA deemed applicable <" + pattern + ">");
return true;
default:
addError("PropertySetter.canContainComponent returned " + containmentType);
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java Wed Oct 25 23:33:56 2006
@@ -92,34 +92,33 @@
* Set the properties for the object that match the <code>prefix</code>
* passed as parameter.
*/
-// public void setProperties(Properties properties, String prefix) {
-// int len = prefix.length();
-//
-// for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
-// String key = (String) e.nextElement();
-//
-// // handle only properties that start with the desired frefix.
-// if (key.startsWith(prefix)) {
-// // ignore key if it contains dots after the prefix
-// if (key.indexOf('.', len + 1) > 0) {
-// // System.err.println("----------Ignoring---["+key
-// // +"], prefix=["+prefix+"].");
-// continue;
-// }
-//
-// String value = OptionHelper.findAndSubst(key, properties);
-//
-// key = key.substring(len);
-//
-// if ("layout".equals(key) && obj instanceof Appender) {
-// continue;
-// }
-//
-// setProperty(key, value);
-// }
-// }
-// }
-
+ // public void setProperties(Properties properties, String prefix) {
+ // int len = prefix.length();
+ //
+ // for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
+ // String key = (String) e.nextElement();
+ //
+ // // handle only properties that start with the desired frefix.
+ // if (key.startsWith(prefix)) {
+ // // ignore key if it contains dots after the prefix
+ // if (key.indexOf('.', len + 1) > 0) {
+ // // System.err.println("----------Ignoring---["+key
+ // // +"], prefix=["+prefix+"].");
+ // continue;
+ // }
+ //
+ // String value = OptionHelper.findAndSubst(key, properties);
+ //
+ // key = key.substring(len);
+ //
+ // if ("layout".equals(key) && obj instanceof Appender) {
+ // continue;
+ // }
+ //
+ // setProperty(key, value);
+ // }
+ // }
+ // }
/**
* Set a property on this PropertySetter's Object. If successful, this method
* will invoke a setter method on the underlying Object. The setter is the one
@@ -227,7 +226,6 @@
if (propertyDescriptor != null) {
Method setterMethod = propertyDescriptor.getWriteMethod();
-
if (setterMethod != null) {
// getLogger().debug(
// "Found setter method for property [{}] in class {}", name,
@@ -295,7 +293,8 @@
}
public void setComponent(String name, Object childComponent) {
- PropertyDescriptor propertyDescriptor = getPropertyDescriptor(name);
+ String dName = Introspector.decapitalize(name);
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(dName);
if (propertyDescriptor == null) {
addWarn("Could not find PropertyDescriptor for [" + name + "] in "
@@ -388,7 +387,10 @@
}
for (int i = 0; i < propertyDescriptors.length; i++) {
+ //System.out.println("Comparing " + name + " against "
+ // + propertyDescriptors[i].getName());
if (name.equals(propertyDescriptors[i].getName())) {
+ //System.out.println("matched");
return propertyDescriptors[i];
}
}
More information about the logback-dev
mailing list