[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.25-43-g888d97d

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Wed Dec 15 22:53:06 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  888d97dcca98ab928da7d67bf6660c293cd47b9e (commit)
      from  2742a97de478cd3fc270223816eaa1c24d13cd82 (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=888d97dcca98ab928da7d67bf6660c293cd47b9e
http://github.com/ceki/logback/commit/888d97dcca98ab928da7d67bf6660c293cd47b9e

commit 888d97dcca98ab928da7d67bf6660c293cd47b9e
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Wed Dec 15 22:49:48 2010 +0100

    ongoing work on compound conversion words

diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassicConverter.java b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassicConverter.java
index 8933733..15bd005 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassicConverter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassicConverter.java
@@ -14,7 +14,6 @@
 package ch.qos.logback.classic.pattern;
 
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.spi.LoggerContextAware;
 import ch.qos.logback.classic.spi.LoggerContextAwareBase;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.Context;
@@ -24,53 +23,10 @@ import ch.qos.logback.core.status.Status;
 
 /**
  * This class serves the super-class of all converters in logback. It extends
- * {@link DynamicConverter} and also implements {@link LoggerContextAware}.
- * 
+ * {@link DynamicConverter}.
+ *
  * @author Ceki Gulcu
  */
-abstract public class ClassicConverter extends DynamicConverter<ILoggingEvent> implements
-    LoggerContextAware {
-
-  LoggerContextAwareBase lcab = new LoggerContextAwareBase();
-
-  public void setLoggerContext(LoggerContext lc) {
-    lcab.setLoggerContext(lc);
-  }
-
-  public void setContext(Context context) {
-    lcab.setContext(context);
-  }
-
-  public Context getContext() {
-    return lcab.getContext();
-  }
-  
-  public void addStatus(Status status) {
-    lcab.addStatus(status);
-  }
-
-  public void addInfo(String msg) {
-    lcab.addInfo(msg);
-  }
-
-  public void addInfo(String msg, Throwable ex) {
-    lcab.addInfo(msg, ex);
-  }
-
-  public void addWarn(String msg) {
-    lcab.addWarn(msg);
-  }
-
-  public void addWarn(String msg, Throwable ex) {
-    lcab.addWarn(msg, ex);
-  }
-
-  public void addError(String msg) {
-    lcab.addError(msg);
-  }
-
-  public void addError(String msg, Throwable ex) {
-    lcab.addError(msg, ex);
-  }
+abstract public class ClassicConverter extends DynamicConverter<ILoggingEvent>  {
 
 }
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java
index 7189586..e72d4b3 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java
@@ -94,7 +94,7 @@ public class ReconfigureOnChangeFilter extends TurboFilter {
   // its values may *not* be incremented sequentially. However, we don't care
   // about the actual value of the field except that from time to time the
   // expression (invocationCounter++ & 0xF) == 0xF) should be true.
-  private int invocationCounter = 0;
+  private long invocationCounter = 0;
 
   @Override
   public FilterReply decide(Marker marker, Logger logger, Level level,
@@ -108,6 +108,7 @@ public class ReconfigureOnChangeFilter extends TurboFilter {
       return FilterReply.NEUTRAL;
     }
 
+    //System.out.println(".");
     synchronized (lock) {
       boolean changed = changeDetected();
       if (changed) {
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
index 8ede4bc..fad905e 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
 import java.util.ArrayList;
 import java.util.List;
 
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.util.StatusPrinter;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -42,7 +44,7 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
   private LoggerContext lc = new LoggerContext();
   Logger logger = lc.getLogger(ConverterTest.class);
   Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
-  
+
   ILoggingEvent le;
   List<String> optionList = new ArrayList<String>();
 
@@ -59,8 +61,8 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
 
   ILoggingEvent makeLoggingEvent(Exception ex) {
     return new LoggingEvent(
-        ch.qos.logback.core.pattern.FormattingConverter.class.getName(),
-        logger, Level.INFO, "Some message", ex, null);
+            ch.qos.logback.core.pattern.FormattingConverter.class.getName(),
+            logger, Level.INFO, "Some message", ex, null);
   }
 
   @Override
@@ -80,7 +82,7 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
     // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some
     // message
     String regex = ISO_REGEX + " INFO " + MAIN_REGEX
-        + " c.q.l.c.pattern.ConverterTest - Some message\\s*";
+            + " c.q.l.c.pattern.ConverterTest - Some message\\s*";
 
     assertTrue(val.matches(regex));
   }
@@ -100,7 +102,7 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
     String val = pl.doLayout(getEventObject());
     // 2008-03-18 21:55:54,250 c.q.l.c.pattern.ConverterTest - Some message
     String regex = ISO_REGEX
-        + " c.q.l.c.p.ConverterTest          - Some message\\s*";
+            + " c.q.l.c.p.ConverterTest          - Some message\\s*";
     assertTrue(val.matches(regex));
   }
 
@@ -109,10 +111,11 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
     pl.setPattern("%property{a}");
     pl.start();
     lc.putProperty("a", "b");
-    
+
     String val = pl.doLayout(getEventObject());
     assertEquals("b", val);
   }
+
   @Test
   public void testNopExeptionHandler() {
     pl.setPattern("%nopex %m%n");
@@ -140,11 +143,29 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
     // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some
     // message
     String regex = ClassicTestConstants.ISO_REGEX + " INFO " + MAIN_REGEX
-        + " c.q.l.c.pattern.ConverterTest - Some message\\s*";
+            + " c.q.l.c.pattern.ConverterTest - Some message\\s*";
     assertTrue(val.matches(regex));
   }
 
   @Test
+  public void replace() {
+//    {
+//      pl.setPattern("%replace(a){'a', 'b'}");
+//      pl.start();
+//      String val = pl.doLayout(getEventObject());
+//      assertEquals("b", val);
+//    }
+    {
+      pl.setPattern("%replace(a1234b){'\\d{4\\}', 'XXXX'}");
+      pl.start();
+      StatusPrinter.print(lc);
+      String val = pl.doLayout(getEventObject());
+      assertEquals("aXXXXb", val);
+    }
+
+  }
+
+  @Test
   public void contextNameTest() {
     pl.setPattern("%contextName");
     lc.setName("aValue");
@@ -168,11 +189,13 @@ public class PatternLayoutTest extends AbstractPatternLayoutBaseTest<ILoggingEve
   public void testConversionRuleSupportInPatternLayout() throws JoranException {
     configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "conversionRule/patternLayout0.xml");
     root.getAppender("LIST");
-    String msg  = "Simon says";
+    String msg = "Simon says";
     logger.debug(msg);
-    StringListAppender<ILoggingEvent> sla = (StringListAppender<ILoggingEvent>)    root.getAppender("LIST");
+    StringListAppender<ILoggingEvent> sla = (StringListAppender<ILoggingEvent>) root.getAppender("LIST");
     assertNotNull(sla);
     assertEquals(1, sla.strList.size());
-    assertEquals(SampleConverter.SAMPLE_STR+" - "+msg, sla.strList.get(0)); 
+    assertEquals(SampleConverter.SAMPLE_STR + " - " + msg, sla.strList.get(0));
   }
+
+
 }
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigurePerf.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigurePerf.java
index 16a36c0..1965b1d 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigurePerf.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigurePerf.java
@@ -33,14 +33,16 @@ import ch.qos.logback.core.joran.spi.JoranException;
 import ch.qos.logback.core.status.InfoStatus;
 import ch.qos.logback.core.testUtil.Env;
 
+import static org.junit.Assert.fail;
+
 public class ReconfigurePerf {
   final static int THREAD_COUNT = 50;
-  final static int LOOP_LEN = 1000 * 1000;
+  //final static int LOOP_LEN = 1000 * 1000;
 
   // the space in the file name mandated by
   // http://jira.qos.ch/browse/LBCORE-119
   final static String CONF_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX
-      + "turbo/scan_perf.xml";
+      + "turbo/scan_perf_barebones.xml";
 
   // it actually takes time for Windows to propagate file modification changes
   // values below 100 milliseconds can be problematic the same propagation
@@ -60,9 +62,9 @@ public class ReconfigurePerf {
     // take into account propagation latency occurs on Linux
     if (Env.isLinux()) {
       sleepBetweenUpdates = 850;
-      totalTestDuration = sleepBetweenUpdates * 5;
+      totalTestDuration = sleepBetweenUpdates * 25;
     } else {
-      totalTestDuration = sleepBetweenUpdates * 10;
+      totalTestDuration = sleepBetweenUpdates * 50;
     }
     harness = new MultiThreadedHarness(totalTestDuration);
   }
@@ -86,11 +88,11 @@ public class ReconfigurePerf {
   public void scan1() throws JoranException, IOException, InterruptedException {
     File file = new File(CONF_FILE_AS_STR);
     configure(file);
-    doRun();
-    doRun();
-    doRun();
+    //doRun();
+    //doRun();
+    //doRun();
     System.out.println("ENTER :");
-    System.in.read();
+    //System.in.read();
     doRun();
   }
 
@@ -99,28 +101,28 @@ public class ReconfigurePerf {
     harness.execute(runnableArray);
   }
   
-  ReconfigureOnChangeFilter initROCF() throws MalformedURLException {
-    ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter();
-    rocf.setContext(loggerContext);
-    File file = new File(CONF_FILE_AS_STR);
-    loggerContext.putObject(CoreConstants.URL_OF_LAST_CONFIGURATION_VIA_JORAN,
-        file.toURI().toURL());
-    rocf.start();
-    return rocf;
-  }
-
-
-  public double directLoop(ReconfigureOnChangeFilter rocf) {
-    long start = System.nanoTime();
-    for (int i = 0; i < LOOP_LEN; i++) {
-      rocf.decide(null, logger, Level.DEBUG, " ", null, null);
-    }
-    long end = System.nanoTime();
-    return (end - start) / (1.0d * LOOP_LEN);
-  }
-
-  void addInfo(String msg, Object o) {
-    loggerContext.getStatusManager().add(new InfoStatus(msg, o));
-  }
+//  ReconfigureOnChangeFilter initROCF() throws MalformedURLException {
+//    ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter();
+//    rocf.setContext(loggerContext);
+//    File file = new File(CONF_FILE_AS_STR);
+//    loggerContext.putObject(CoreConstants.URL_OF_LAST_CONFIGURATION_VIA_JORAN,
+//        file.toURI().toURL());
+//    rocf.start();
+//    return rocf;
+//  }
+
+
+//  public double directLoop(ReconfigureOnChangeFilter rocf) {
+//    long start = System.nanoTime();
+//    for (int i = 0; i < LOOP_LEN; i++) {
+//      rocf.decide(null, logger, Level.DEBUG, " ", null, null);
+//    }
+//    long end = System.nanoTime();
+//    return (end - start) / (1.0d * LOOP_LEN);
+//  }
+//
+//  void addInfo(String msg, Object o) {
+//    loggerContext.getStatusManager().add(new InfoStatus(msg, o));
+//  }
 
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/DynamicConverter.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/DynamicConverter.java
index cdb0958..14a8033 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/DynamicConverter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/DynamicConverter.java
@@ -15,10 +15,16 @@ package ch.qos.logback.core.pattern;
 
 import java.util.List;
 
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.spi.ContextAware;
+import ch.qos.logback.core.spi.ContextAwareBase;
 import ch.qos.logback.core.spi.LifeCycle;
+import ch.qos.logback.core.status.Status;
 
 abstract public class DynamicConverter<E> extends FormattingConverter<E>
-    implements LifeCycle {
+    implements LifeCycle, ContextAware {
+
+  ContextAwareBase cab = new ContextAwareBase(this);
 
   // Contains a list of option Strings.
   private List<String> optionList;
@@ -67,4 +73,40 @@ abstract public class DynamicConverter<E> extends FormattingConverter<E>
   protected List<String> getOptionList() {
     return optionList;
   }
+
+  public void setContext(Context context) {
+    cab.setContext(context);
+  }
+
+  public Context getContext() {
+    return cab.getContext();
+  }
+
+  public void addStatus(Status status) {
+    cab.addStatus(status);
+  }
+
+  public void addInfo(String msg) {
+    cab.addInfo(msg);
+  }
+
+  public void addInfo(String msg, Throwable ex) {
+    cab.addInfo(msg, ex);
+  }
+
+  public void addWarn(String msg) {
+    cab.addWarn(msg);
+  }
+
+  public void addWarn(String msg, Throwable ex) {
+    cab.addWarn(msg, ex);
+  }
+
+  public void addError(String msg) {
+    cab.addError(msg);
+  }
+
+  public void addError(String msg, Throwable ex) {
+    cab.addError(msg, ex);
+  }
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/ReplacingCompositeConverter.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/ReplacingCompositeConverter.java
index c5e29ef..55ef3ff 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/ReplacingCompositeConverter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/ReplacingCompositeConverter.java
@@ -13,19 +13,45 @@
  */
 package ch.qos.logback.core.pattern;
 
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.spi.ContextAware;
+
 import java.util.List;
+import java.util.regex.Pattern;
 
 public class ReplacingCompositeConverter<E> extends CompositeConverter<E> {
 
+  Pattern pattern;
   String regex;
-  String by;
+  String replacement;
 
   public void start() {
-     final List<String> optionList = getOptionList();
-     regex = optionList.get(0);
+    final List<String> optionList = getOptionList();
+    if (optionList == null) {
+      addError("at least two options are expected whereas you have declared none");
+      return;
+    }
+
+    int numOpts = optionList.size();
+
+    if (numOpts < 2) {
+      addError("at least two options are expected whereas you have declared only " + numOpts + "as [" + optionList + "]");
+      return;
+    }
+    regex = optionList.get(0);
+    pattern = Pattern.compile(regex);
+
+    //.matcher(this).replaceAll(replacement);
+
+    replacement = optionList.get(1);
+    System.out.println("regex="+regex);
+    super.start();
   }
+
   @Override
   String transform(String in) {
-    return null;  //To change body of implemented methods use File | Settings | File Templates.
+    if (!started)
+      return in;
+    return pattern.matcher(in).replaceAll(replacement);
   }
-}
+}
\ No newline at end of file
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/OptionTokenizer.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/OptionTokenizer.java
index ad4c762..369a67f 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/OptionTokenizer.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/OptionTokenizer.java
@@ -16,6 +16,7 @@ package ch.qos.logback.core.pattern.parser;
 import java.util.ArrayList;
 import java.util.List;
 
+import ch.qos.logback.core.pattern.util.AsIsEscapeUtil;
 import ch.qos.logback.core.pattern.util.IEscapeUtil;
 import ch.qos.logback.core.pattern.util.RegularEscapeUtil;
 
@@ -43,7 +44,7 @@ public class OptionTokenizer {
    * @param pattern
    */
   OptionTokenizer(String pattern) {
-    this(pattern, new RegularEscapeUtil());
+    this(pattern, new AsIsEscapeUtil());
   }
   
   OptionTokenizer(String pattern, IEscapeUtil escapeUtil) {
@@ -68,6 +69,8 @@ public class OptionTokenizer {
         case '\r':
         case '\n':
           break;
+        case COMMA_CHAR:
+          break;
         case SINGLE_QUOTE_CHAR:
         case DOUBLE_QUOTE_CHAR:
           state = QUOTED_COLLECTING_STATE;
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
index 19d8311..085947a 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.pattern.util.IEscapeUtil;
 import ch.qos.logback.core.pattern.util.RegularEscapeUtil;
+import ch.qos.logback.core.pattern.util.RestrictedEscapeUtil;
 
 /**
  * <p>
@@ -49,11 +50,14 @@ class TokenStream {
   private static final int FORMAT_MODIFIER_STATE = 1;
   private static final int KEYWORD_STATE = 2;
   private static final int OPTION_STATE = 3;
+  private static final int RIGHT_PARENTHESIS_STATE = 4;
 
   final String pattern;
   final int patternLength;
   final IEscapeUtil escapeUtil;
 
+  final IEscapeUtil optionEscapeUtil = new RestrictedEscapeUtil();
+
   int state = LITERAL_STATE;
   int pointer = 0;
 
@@ -81,30 +85,21 @@ class TokenStream {
       pointer++;
 
       switch (state) {
-
         case LITERAL_STATE:
           handleLiteralState(c, tokenList, buf);
           break;
-        //
         case FORMAT_MODIFIER_STATE:
           handleFormatModifierState(c, tokenList, buf);
           break;
         case OPTION_STATE:
-          switch (c) {
-            case CURLY_RIGHT:
-              addValuedToken(Token.OPTION, buf, tokenList);
-              state = LITERAL_STATE;
-              break;
-            case ESCAPE_CHAR:
-              escape("%{}", buf);
-              break;
-            default:
-              buf.append(c);
-          }
+          handleOptionState(c, tokenList, buf);
           break;
         case KEYWORD_STATE:
           handleKeywordState(c, tokenList, buf);
           break;
+        case RIGHT_PARENTHESIS_STATE:
+          handleRightParenthesisState(c, tokenList, buf);
+          break;
 
         default:
       }
@@ -117,7 +112,9 @@ class TokenStream {
         break;
       case KEYWORD_STATE:
         tokenList.add(new Token(Token.SIMPLE_KEYWORD, buf.toString()));
-        buf.setLength(0);
+        break;
+      case RIGHT_PARENTHESIS_STATE:
+        tokenList.add(Token.RIGHT_PARENTHESIS_TOKEN);
         break;
 
       case FORMAT_MODIFIER_STATE:
@@ -128,6 +125,38 @@ class TokenStream {
     return tokenList;
   }
 
+  private void handleRightParenthesisState(char c, List<Token> tokenList, StringBuffer buf) {
+    tokenList.add(Token.RIGHT_PARENTHESIS_TOKEN);
+    switch (c) {
+      case CoreConstants.RIGHT_PARENTHESIS_CHAR:
+        break;
+      case CURLY_LEFT:
+        state = OPTION_STATE;
+        break;
+      case ESCAPE_CHAR:
+        escape("%{}", buf);
+        state = LITERAL_STATE;
+        break;
+      default:
+        buf.append(c);
+        state = LITERAL_STATE;
+    }
+  }
+
+  private void handleOptionState(char c, List<Token> tokenList, StringBuffer buf) {
+    switch (c) {
+      case CURLY_RIGHT:
+        addValuedToken(Token.OPTION, buf, tokenList);
+        state = LITERAL_STATE;
+        break;
+      case ESCAPE_CHAR:
+        optionEscape("}", buf);
+        break;
+      default:
+        buf.append(c);
+    }
+  }
+
   private void handleFormatModifierState(char c, List<Token> tokenList, StringBuffer buf) {
     if (c == CoreConstants.LEFT_PARENTHESIS_CHAR) {
       addValuedToken(Token.FORMAT_MODIFIER, buf, tokenList);
@@ -155,13 +184,8 @@ class TokenStream {
         break;
 
       case CoreConstants.RIGHT_PARENTHESIS_CHAR:
-        if (buf.length() >= 1 && buf.charAt(buf.length() - 1) == '\\') {
-          buf.deleteCharAt(buf.length() - 1);
-          buf.append(CoreConstants.RIGHT_PARENTHESIS_CHAR);
-        } else {
-          addValuedToken(Token.LITERAL, buf, tokenList);
-          tokenList.add(Token.RIGHT_PARENTHESIS_TOKEN);
-        }
+        addValuedToken(Token.LITERAL, buf, tokenList);
+        state = RIGHT_PARENTHESIS_STATE;
         break;
 
       default:
@@ -170,11 +194,12 @@ class TokenStream {
   }
 
   private void handleKeywordState(char c, List<Token> tokenList, StringBuffer buf) {
-    if (c == CURLY_LEFT) {
+
+    if (Character.isJavaIdentifierPart(c)) {
+      buf.append(c);
+    } else if (c == CURLY_LEFT) {
       addValuedToken(Token.SIMPLE_KEYWORD, buf, tokenList);
       state = OPTION_STATE;
-    } else if (Character.isJavaIdentifierPart(c)) {
-      buf.append(c);
     } else if (c == CoreConstants.LEFT_PARENTHESIS_CHAR) {
       addValuedToken(Token.COMPOSITE_KEYWORD, buf, tokenList);
       state = LITERAL_STATE;
@@ -182,12 +207,12 @@ class TokenStream {
       addValuedToken(Token.SIMPLE_KEYWORD, buf, tokenList);
       tokenList.add(Token.PERCENT_TOKEN);
       state = FORMAT_MODIFIER_STATE;
+    } else if (c == CoreConstants.RIGHT_PARENTHESIS_CHAR) {
+      addValuedToken(Token.SIMPLE_KEYWORD, buf, tokenList);
+      state = RIGHT_PARENTHESIS_STATE;
     } else {
       addValuedToken(Token.SIMPLE_KEYWORD, buf, tokenList);
-      if (c == CoreConstants.RIGHT_PARENTHESIS_CHAR) {
-        // if c is a right parenthesis, then add it as such
-        tokenList.add(Token.RIGHT_PARENTHESIS_TOKEN);
-      } else if (c == ESCAPE_CHAR) {
+      if (c == ESCAPE_CHAR) {
         if ((pointer < patternLength)) {
           char next = pattern.charAt(pointer++);
           escapeUtil.escape("%()", buf, next, pointer);
@@ -206,6 +231,16 @@ class TokenStream {
     }
   }
 
+  void optionEscape(String escapeChars, StringBuffer buf) {
+    if ((pointer < patternLength)) {
+      char next = pattern.charAt(pointer++);
+      optionEscapeUtil.escape(escapeChars, buf, next, pointer);
+    }
+  }
+
+
+
+
   private void addValuedToken(int type, StringBuffer buf, List<Token> tokenList) {
     if (buf.length() > 0) {
       tokenList.add(new Token(type, buf.toString()));
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AlmostAsIsEscapeUtil.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AlmostAsIsEscapeUtil.java
index f9103cd..959c82d 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AlmostAsIsEscapeUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AlmostAsIsEscapeUtil.java
@@ -21,7 +21,7 @@ import ch.qos.logback.core.rolling.helper.FileNamePattern;
  * 
  * @author Ceki G&uuml;lc&uuml;
  */
-public class AlmostAsIsEscapeUtil implements IEscapeUtil {
+public class AlmostAsIsEscapeUtil extends RestrictedEscapeUtil {
 
   /**
    * Do not perform any character escaping, except for '%', and ')'.
@@ -40,16 +40,6 @@ public class AlmostAsIsEscapeUtil implements IEscapeUtil {
    */
   public void escape(String escapeChars, StringBuffer buf, char next,
       int pointer) {
-
-    if (next == CoreConstants.PERCENT_CHAR
-        || next == CoreConstants.RIGHT_PARENTHESIS_CHAR) {
-      buf.append(next);
-    } else {
-      // restitute the escape char (because it was consumed
-      // before this method was called).
-      buf.append("\\");
-      // restitute the next character
-      buf.append(next);
-    }
+    super.escape(""+CoreConstants.PERCENT_CHAR+CoreConstants.RIGHT_PARENTHESIS_CHAR, buf, next, pointer);
   }
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AsIsEscapeUtil.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AsIsEscapeUtil.java
new file mode 100644
index 0000000..224bad9
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/AsIsEscapeUtil.java
@@ -0,0 +1,38 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ *   or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.pattern.util;
+
+import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.rolling.helper.FileNamePattern;
+
+/**
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class AsIsEscapeUtil implements IEscapeUtil {
+
+  /**
+   * Do not perform any character escaping.
+   * <p/>
+   * Note that this method assumes that it is called after the escape character
+   * has been consumed.
+   */
+  public void escape(String escapeChars, StringBuffer buf, char next,
+                     int pointer) {
+    // restitute the escape char (because it was consumed
+    // before this method was called).
+    buf.append("\\");
+    // restitute the next character
+    buf.append(next);
+  }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RestrictedEscapeUtil.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RestrictedEscapeUtil.java
new file mode 100644
index 0000000..219d8ae
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RestrictedEscapeUtil.java
@@ -0,0 +1,37 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ *   or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.pattern.util;
+
+/**
+ * This implementation is intended for use in PatternLayout.
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class RestrictedEscapeUtil implements IEscapeUtil {
+
+  public void escape(String escapeChars, StringBuffer buf, char next,
+                     int pointer) {
+    if (escapeChars.indexOf(next) >= 0) {
+      buf.append(next);
+    } else {
+      // restitute the escape char (because it was consumed
+      // before this method was called).
+      buf.append("\\");
+      // restitute the next character
+      buf.append(next);
+    }
+  }
+
+
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java b/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java
index 133bbbf..874a03d 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java
@@ -29,6 +29,14 @@ import ch.qos.logback.core.status.WarnStatus;
 public class ContextAwareBase implements ContextAware {
   private int noContextWarning = 0;
   protected Context context;
+  final Object declaredOrigin;
+
+  public ContextAwareBase() {
+    declaredOrigin = this;
+  }
+  public ContextAwareBase(Object declaredOrigin) {
+    this.declaredOrigin = declaredOrigin;
+  }
 
   public void setContext(Context context) {
     if (this.context == null) {
@@ -56,7 +64,7 @@ public class ContextAwareBase implements ContextAware {
    * @return the declared origin, by default 'this'
    */ 
   protected Object getDeclaredOrigin() {
-    return this;
+    return declaredOrigin;
   }
 
   public void addStatus(Status status) {
diff --git a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/OptionTokenizerTest.java b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/OptionTokenizerTest.java
index e1a3d53..6c8db70 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/OptionTokenizerTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/OptionTokenizerTest.java
@@ -118,6 +118,20 @@ public class OptionTokenizerTest  {
       witness.add("b");
       assertEquals(witness, ol);
     }
+    {
+      List ol = new OptionTokenizer("'a', b").tokenize();
+      List<String> witness = new ArrayList<String>();
+      witness.add("a");
+      witness.add("b");
+      assertEquals(witness, ol);
+    }
+    {
+      List ol = new OptionTokenizer("'', b").tokenize();
+      List<String> witness = new ArrayList<String>();
+      witness.add("");
+      witness.add("b");
+      assertEquals(witness, ol);
+    }
   }
 
 }
\ No newline at end of file
diff --git a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/TokenStreamTest.java b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/TokenStreamTest.java
index c9d12a0..751f515 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/TokenStreamTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/TokenStreamTest.java
@@ -19,6 +19,7 @@ import static org.junit.Assert.fail;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 import ch.qos.logback.core.pattern.util.AlmostAsIsEscapeUtil;

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

Summary of changes:
 .../logback/classic/pattern/ClassicConverter.java  |   50 +----------
 .../classic/turbo/ReconfigureOnChangeFilter.java   |    3 +-
 .../ch/qos/logback/classic/PatternLayoutTest.java  |   43 +++++++--
 .../qos/logback/classic/turbo/ReconfigurePerf.java |   64 +++++++-------
 .../qos/logback/core/pattern/DynamicConverter.java |   44 +++++++++-
 .../core/pattern/ReplacingCompositeConverter.java  |   36 +++++++-
 .../core/pattern/parser/OptionTokenizer.java       |    5 +-
 .../logback/core/pattern/parser/TokenStream.java   |   91 ++++++++++++++------
 .../core/pattern/util/AlmostAsIsEscapeUtil.java    |   14 +---
 .../logback/core/pattern/util/AsIsEscapeUtil.java  |   38 ++++++++
 .../core/pattern/util/RestrictedEscapeUtil.java    |   37 ++++++++
 .../ch/qos/logback/core/spi/ContextAwareBase.java  |   10 ++-
 .../core/pattern/parser/OptionTokenizerTest.java   |   14 +++
 .../core/pattern/parser/TokenStreamTest.java       |    1 +
 14 files changed, 313 insertions(+), 137 deletions(-)
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/pattern/util/AsIsEscapeUtil.java
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/pattern/util/RestrictedEscapeUtil.java


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


More information about the logback-dev mailing list