[logback-dev] branch, master, updated. b3f2333b924d4c811059863e92c5b7742580fe47

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Nov 10 22:22:44 CET 2009


The branch, master has been updated
       via  b3f2333b924d4c811059863e92c5b7742580fe47 (commit)
      from  baba96b8e2a916ecee6d3fda41c7040535f5b175 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=b3f2333b924d4c811059863e92c5b7742580fe47
http://github.com/ceki/logback/commit/b3f2333b924d4c811059863e92c5b7742580fe47

commit b3f2333b924d4c811059863e92c5b7742580fe47
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Nov 10 22:20:58 2009 +0100

    - minor adjustments in the comments
    - editing of filters.html

diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java b/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java
index 232c689..0bfd020 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java
@@ -28,22 +28,20 @@ import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
 import ch.qos.logback.core.boolex.Matcher;
 
+public class JaninoEventEvaluator extends
+    JaninoEventEvaluatorBase<ILoggingEvent> {
 
-
-public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent> {
-
-  
   public final static String IMPORT_LEVEL = "import ch.qos.logback.classic.Level;\r\n";
-  
+
   public final static List<String> DEFAULT_PARAM_NAME_LIST = new ArrayList<String>();
   public final static List<Class> DEFAULT_PARAM_TYPE_LIST = new ArrayList<Class>();
-  
+
   static {
     DEFAULT_PARAM_NAME_LIST.add("DEBUG");
     DEFAULT_PARAM_NAME_LIST.add("INFO");
     DEFAULT_PARAM_NAME_LIST.add("WARN");
     DEFAULT_PARAM_NAME_LIST.add("ERROR");
-    
+
     DEFAULT_PARAM_NAME_LIST.add("event");
     DEFAULT_PARAM_NAME_LIST.add("message");
 
@@ -56,12 +54,12 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
     DEFAULT_PARAM_NAME_LIST.add("mdc");
     DEFAULT_PARAM_NAME_LIST.add("throwableProxy");
     DEFAULT_PARAM_NAME_LIST.add("throwable");
-    
+
     DEFAULT_PARAM_TYPE_LIST.add(int.class);
     DEFAULT_PARAM_TYPE_LIST.add(int.class);
     DEFAULT_PARAM_TYPE_LIST.add(int.class);
     DEFAULT_PARAM_TYPE_LIST.add(int.class);
-    
+
     DEFAULT_PARAM_TYPE_LIST.add(ILoggingEvent.class);
     DEFAULT_PARAM_TYPE_LIST.add(String.class);
     DEFAULT_PARAM_TYPE_LIST.add(String.class);
@@ -74,11 +72,11 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
     DEFAULT_PARAM_TYPE_LIST.add(IThrowableProxy.class);
     DEFAULT_PARAM_TYPE_LIST.add(Throwable.class);
   }
-  
-  
+
   public JaninoEventEvaluator() {
-    
+
   }
+
   protected String getDecoratedExpression() {
     return IMPORT_LEVEL + getExpression();
   }
@@ -87,18 +85,18 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
     List<String> fullNameList = new ArrayList<String>();
     fullNameList.addAll(DEFAULT_PARAM_NAME_LIST);
 
-    for(int i = 0; i < matcherList.size(); i++) {
+    for (int i = 0; i < matcherList.size(); i++) {
       Matcher m = (Matcher) matcherList.get(i);
       fullNameList.add(m.getName());
     }
-    
+
     return (String[]) fullNameList.toArray(CoreConstants.EMPTY_STRING_ARRAY);
   }
 
   protected Class[] getParameterTypes() {
     List<Class> fullTypeList = new ArrayList<Class>();
     fullTypeList.addAll(DEFAULT_PARAM_TYPE_LIST);
-    for(int i = 0; i < matcherList.size(); i++) {
+    for (int i = 0; i < matcherList.size(); i++) {
       fullTypeList.add(Matcher.class);
     }
     return (Class[]) fullTypeList.toArray(CoreConstants.EMPTY_CLASS_ARRAY);
@@ -106,30 +104,34 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
 
   protected Object[] getParameterValues(ILoggingEvent loggingEvent) {
     final int matcherListSize = matcherList.size();
-    
+
     int i = 0;
-    Object[] values = new Object[DEFAULT_PARAM_NAME_LIST.size()+matcherListSize];
+    Object[] values = new Object[DEFAULT_PARAM_NAME_LIST.size()
+        + matcherListSize];
 
     values[i++] = Level.DEBUG_INTEGER;
     values[i++] = Level.INFO_INTEGER;
     values[i++] = Level.WARN_INTEGER;
     values[i++] = Level.ERROR_INTEGER;
-    
+
     values[i++] = loggingEvent;
-    values[i++] = loggingEvent.getMessage();    
-    values[i++] = loggingEvent.getFormattedMessage();   
+    values[i++] = loggingEvent.getMessage();
+    values[i++] = loggingEvent.getFormattedMessage();
     values[i++] = loggingEvent.getLoggerName();
     values[i++] = loggingEvent.getLoggerContextVO();
     values[i++] = loggingEvent.getLevel().toInteger();
     values[i++] = new Long(loggingEvent.getTimeStamp());
+    // In order to avoid NullPointerException, we could push a dummy marker if
+    // the event's marker is null. However, this would surprise user who
+    // expect to see a null marker instead of a dummy one.
     values[i++] = loggingEvent.getMarker();
     values[i++] = loggingEvent.getMDCPropertyMap();
-    
+
     IThrowableProxy iThrowableProxy = loggingEvent.getThrowableProxy();
-    
+
     if (iThrowableProxy != null) {
       values[i++] = iThrowableProxy;
-      if(iThrowableProxy instanceof ThrowableProxy) {
+      if (iThrowableProxy instanceof ThrowableProxy) {
         values[i++] = ((ThrowableProxy) iThrowableProxy).getThrowable();
       } else {
         values[i++] = null;
@@ -138,12 +140,11 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
       values[i++] = null;
       values[i++] = null;
     }
-    
-    
-    for(int j = 0; j < matcherListSize; j++) {
+
+    for (int j = 0; j < matcherListSize; j++) {
       values[i++] = (Matcher) matcherList.get(j);
     }
-    
+
     return values;
   }
 
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
index 8be5a62..17eabe8 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
@@ -13,6 +13,7 @@
  */
 package ch.qos.logback.classic.boolex;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -31,15 +32,22 @@ import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.boolex.EvaluationException;
 import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
 import ch.qos.logback.core.boolex.Matcher;
+import ch.qos.logback.core.filter.EvaluatorFilter;
+import ch.qos.logback.core.spi.FilterReply;
+import ch.qos.logback.core.util.StatusPrinter;
 
-public class JaninoEventEvaluatorTest  {
+public class JaninoEventEvaluatorTest {
 
   LoggerContext loggerContext = new LoggerContext();
   Logger logger = loggerContext.getLogger(ConverterTest.class);
 
   Matcher matcherX = new Matcher();
 
+  JaninoEventEvaluator jee = new JaninoEventEvaluator();
+
   public JaninoEventEvaluatorTest() {
+    jee.setContext(loggerContext);
+
     matcherX.setName("x");
     matcherX.setRegex("^Some\\s.*");
     matcherX.start();
@@ -55,33 +63,27 @@ public class JaninoEventEvaluatorTest  {
 
   @Test
   public void testBasic() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("message.equals(\"Some message\")");
-    jee.setContext(loggerContext);
     jee.start();
 
     ILoggingEvent event = makeLoggingEvent(null);
-    //System.out.println(event);
+    // System.out.println(event);
     assertTrue(jee.evaluate(event));
   }
 
   @Test
   public void testLevel() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("level > DEBUG");
-    jee.setContext(loggerContext);
     jee.start();
 
     ILoggingEvent event = makeLoggingEvent(null);
-    //System.out.println(event);
+    // System.out.println(event);
     assertTrue(jee.evaluate(event));
   }
 
   @Test
   public void testtimeStamp() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("timeStamp > 10");
-    jee.setContext(loggerContext);
     jee.start();
 
     ILoggingEvent event = makeLoggingEvent(null);
@@ -90,10 +92,7 @@ public class JaninoEventEvaluatorTest  {
 
   @Test
   public void testWithMatcher() throws Exception {
-
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("x.matches(message)");
-    jee.setContext(loggerContext);
     jee.addMatcher(matcherX);
     jee.start();
 
@@ -102,11 +101,8 @@ public class JaninoEventEvaluatorTest  {
   }
 
   @Test
-  public void testMarker() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
+  public void marker() throws Exception {
     jee.setExpression("marker.contains(\"BLUE\")");
-    jee.setContext(loggerContext);
-    jee.addMatcher(matcherX);
     jee.start();
 
     LoggingEvent event = makeLoggingEvent(null);
@@ -115,11 +111,8 @@ public class JaninoEventEvaluatorTest  {
   }
 
   @Test
-  public void testWithNullMarker_LBCORE_118() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
+  public void withNullMarker_LBCORE_118() throws Exception {
     jee.setExpression("marker.contains(\"BLUE\")");
-    jee.setContext(loggerContext);
-    jee.addMatcher(matcherX);
     jee.start();
 
     ILoggingEvent event = makeLoggingEvent(null);
@@ -127,36 +120,32 @@ public class JaninoEventEvaluatorTest  {
       jee.evaluate(event);
       fail("We should not reach this point");
     } catch (EvaluationException ee) {
-
+      // received an exception as expected
     }
   }
 
   @Test
-  public void testWithNullMarker() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
+  public void evaluatorFilterWithNullMarker_LBCORE_118() throws Exception {
+    EvaluatorFilter<ILoggingEvent> ef = new EvaluatorFilter<ILoggingEvent>();
+    ef.setContext(loggerContext);
+
+    ef.setOnMatch(FilterReply.ACCEPT);
+    ef.setOnMismatch(FilterReply.DENY);
+
     jee.setExpression("marker.contains(\"BLUE\")");
-    jee.setContext(loggerContext);
-    jee.addMatcher(matcherX);
     jee.start();
 
+    ef.setEvaluator(jee);
+    ef.start();
     ILoggingEvent event = makeLoggingEvent(null);
-    try {
-      jee.evaluate(event);
-      fail("We should not reach this point");
-    } catch (EvaluationException ee) {
-
-    }
+    assertEquals(FilterReply.NEUTRAL, ef.decide(event));
+    
   }
 
-  
-  
   @Test
   public void testComplex() throws Exception {
-
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee
         .setExpression("level >= INFO && x.matches(message) && marker.contains(\"BLUE\")");
-    jee.setContext(loggerContext);
     jee.addMatcher(matcherX);
     jee.start();
 
@@ -166,35 +155,23 @@ public class JaninoEventEvaluatorTest  {
   }
 
   /**
-   * check that evaluator with bogis exp does not start
+   * check that evaluator with bogus exp does not start
    * 
    * @throws Exception
    */
   @Test
   public void testBogusExp1() {
-
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("mzzzz.get(\"key\").equals(null)");
-    jee.setContext(loggerContext);
     jee.setName("bogus");
     jee.start();
 
     assertFalse(jee.isStarted());
-
-    // StatusPrinter.print(loggerContext);
-    // LoggingEvent event = makeLoggingEvent(null);
-    // event.setMarker(MarkerFactory.getMarker("BLUE"));
-    //    
-    // jee.evaluate(event);
   }
 
   // check that eval stops after errors
   @Test
   public void testBogusExp2() {
-
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("mdc.get(\"keyXN89\").equals(null)");
-    jee.setContext(loggerContext);
     jee.setName("bogus");
     jee.start();
 
@@ -222,19 +199,17 @@ public class JaninoEventEvaluatorTest  {
   // with 10 parameters 510 nanos (all levels + fields)
   void loop(JaninoEventEvaluator jee, String msg) throws Exception {
     ILoggingEvent event = makeLoggingEvent(null);
-    //final long start = System.nanoTime();
+    // final long start = System.nanoTime();
     for (int i = 0; i < LEN; i++) {
       jee.evaluate(event);
     }
-    //final long end = System.nanoTime();
-    //System.out.println(msg + (end - start) / LEN + " nanos");
+    // final long end = System.nanoTime();
+    // System.out.println(msg + (end - start) / LEN + " nanos");
   }
 
   @Test
   public void testLoop1() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("timeStamp > 10");
-    jee.setContext(loggerContext);
     jee.start();
 
     loop(jee, "timestamp > 10]: ");
@@ -242,32 +217,25 @@ public class JaninoEventEvaluatorTest  {
 
   @Test
   public void testLoop2() throws Exception {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("x.matches(message)");
-    jee.setContext(loggerContext);
     jee.addMatcher(matcherX);
     jee.start();
 
     loop(jee, "x.matches(message): ");
   }
 
-  @Test 
+  @Test
   public void throwable_LBCLASSIC_155_I() throws EvaluationException {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("throwable instanceof java.io.IOException");
-    jee.setContext(loggerContext);
     jee.start();
 
     LoggingEvent event = makeLoggingEvent(new IOException(""));
     assertTrue(jee.evaluate(event));
   }
 
-  
-  @Test 
+  @Test
   public void throwable_LBCLASSIC_155_II() throws EvaluationException {
-    JaninoEventEvaluator jee = new JaninoEventEvaluator();
     jee.setExpression("throwableProxy.getClassName().contains(\"IO\")");
-    jee.setContext(loggerContext);
     jee.start();
 
     LoggingEvent event = makeLoggingEvent(new IOException(""));
diff --git a/logback-examples/src/main/java/chapter6/evaluatorWithMatcher.xml b/logback-examples/src/main/java/chapter6/evaluatorWithMatcher.xml
index 64d0efb..f2aab92 100644
--- a/logback-examples/src/main/java/chapter6/evaluatorWithMatcher.xml
+++ b/logback-examples/src/main/java/chapter6/evaluatorWithMatcher.xml
@@ -9,7 +9,7 @@
           <regex>statement [13579]</regex>
         </matcher>
         
-        <expression>message.contains("billing") || odd.matches(formattedMessage)</expression>
+        <expression>odd.matches(formattedMessage)</expression>
       </evaluator>
       <OnMismatch>NEUTRAL</OnMismatch>
       <OnMatch>DENY</OnMatch>
diff --git a/logback-site/src/site/pages/manual/filters.html b/logback-site/src/site/pages/manual/filters.html
index 3b61138..b2aa23c 100644
--- a/logback-site/src/site/pages/manual/filters.html
+++ b/logback-site/src/site/pages/manual/filters.html
@@ -348,7 +348,9 @@ public class SampleFilter extends Filter&gt;ILoggingEvent> {
 				<td>marker</td>
 				<td><code>Marker</code></td>
         <td>The <code>Marker</code> object associated with the logging
-        request.
+        request. Note that marker can be null and it is your
+        responsibility to check for this condition in order to avoid
+        <code>NullPointerException</code>.
 				</td>
 			</tr>
 			<tr>
@@ -502,7 +504,7 @@ java chapter6.FilterEvents src/main/java/chapter6/basicConfiguration.xml
 
 <em>Example 6.<span class="autoEx"/>: Defining matchers in an event evaluator (logback-examples/src/main/java/chapter6/evaluatorWithMatcher.xml)</em>
 
-    <pre class="prettyprint source longline">&lt;configuration debug="true">
+    <pre class="prettyprint source">&lt;configuration debug="true">
 
   &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
     &lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter">
@@ -513,7 +515,7 @@ java chapter6.FilterEvents src/main/java/chapter6/basicConfiguration.xml
           &lt;regex>statement [13579]&lt;/regex>
         &lt;/matcher>
         
-        &lt;expression>message.contains("billing") || odd.matches(formattedMessage)&lt;/expression></b>
+        &lt;expression>odd.matches(formattedMessage)&lt;/expression></b>
       &lt;/evaluator>
       &lt;OnMismatch>NEUTRAL&lt;/OnMismatch>
       &lt;OnMatch>DENY&lt;/OnMatch>
@@ -533,13 +535,14 @@ java chapter6.FilterEvents src/main/java/chapter6/basicConfiguration.xml
     <p>we obtain:
 		</p>
 		
-    <p class="source">220  [main] INFO  chapter6.FilterEvents - logging statement 0
-223  [main] INFO  chapter6.FilterEvents - logging statement 2
-223  [main] INFO  chapter6.FilterEvents - logging statement 4
-225  [main] INFO  chapter6.FilterEvents - logging statement 8</p>
+    <p class="source">260  [main] INFO  chapter6.FilterEvents - logging statement 0
+264  [main] INFO  chapter6.FilterEvents - logging statement 2
+264  [main] INFO  chapter6.FilterEvents - logging statement 4
+266  [main] ERROR chapter6.FilterEvents - billing statement 6
+266  [main] INFO  chapter6.FilterEvents - logging statement 8</p>
 
     <p>In case you need to define additional matchers, you can do so by
-    adding further <code>&lt;matcher></code> elements.
+    adding further <code>&lt;matcher></code> elements.</p>
 
     <!-- ================================================================ -->
     <!-- ===================== TURBO FILTER ============================= -->

-----------------------------------------------------------------------

Summary of changes:
 .../classic/boolex/JaninoEventEvaluator.java       |   55 ++++++------
 .../classic/boolex/JaninoEventEvaluatorTest.java   |   94 +++++++-------------
 .../main/java/chapter6/evaluatorWithMatcher.xml    |    2 +-
 logback-site/src/site/pages/manual/filters.html    |   19 +++--
 4 files changed, 71 insertions(+), 99 deletions(-)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list