[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-17-g3884318

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Wed Feb 10 19:23:32 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  3884318ebb54e4020756c0ae289d12f02a2f7aec (commit)
      from  7cc45624e0baed34f3750e7a8175a83b1da4c9cf (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=3884318ebb54e4020756c0ae289d12f02a2f7aec
http://github.com/ceki/logback/commit/3884318ebb54e4020756c0ae289d12f02a2f7aec

commit 3884318ebb54e4020756c0ae289d12f02a2f7aec
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Wed Feb 10 19:21:05 2010 +0100

    Fixed LBCORE-130. FileNamePattern no longer treats parenthesis as special.

diff --git a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
index a57425f..74cfd1b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
@@ -71,6 +71,8 @@ public class CoreConstants {
   
   
   public final static char PERCENT_CHAR = '%';
+  public static final char LEFT_PARENTHESIS_CHAR = '(';
+  public static final char RIGHT_PARENTHESIS_CHAR = ')';
   
   /** 
    * Number of rows before in an HTML table before, 
@@ -110,5 +112,4 @@ public class CoreConstants {
    * context.
    */
   public static final String HOSTNAME_KEY = "HOSTNAME";
-  
 }
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 522964d..8e9abff 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
@@ -38,8 +38,6 @@ class TokenStream {
 
   private static final char ESCAPE_CHAR = '\\';
   private static final char PERCENT_CHAR = CoreConstants.PERCENT_CHAR; 
-  private static final char LEFT_PARENTHESIS = '(';
-  private static final char RIGHT_PARENTHESIS = ')';
   private static final char CURLY_LEFT = '{';
   private static final char CURLY_RIGHT = '}';
 
@@ -90,10 +88,10 @@ class TokenStream {
           state = FORMAT_MODIFIER_STATE;
           break;
 
-        case RIGHT_PARENTHESIS:
+        case CoreConstants.RIGHT_PARENTHESIS_CHAR:
           if (buf.length() >= 1 && buf.charAt(buf.length() - 1) == '\\') {
             buf.deleteCharAt(buf.length() - 1);
-            buf.append(RIGHT_PARENTHESIS);
+            buf.append(CoreConstants.RIGHT_PARENTHESIS_CHAR);
           } else {
             addValuedToken(Token.LITERAL, buf, tokenList);
             tokenList.add(Token.RIGHT_PARENTHESIS_TOKEN);
@@ -106,7 +104,7 @@ class TokenStream {
         break;
       //
       case FORMAT_MODIFIER_STATE:
-        if (c == LEFT_PARENTHESIS) {
+        if (c == CoreConstants.LEFT_PARENTHESIS_CHAR) {
           addValuedToken(Token.FORMAT_MODIFIER, buf, tokenList);
           tokenList.add(Token.LEFT_PARENTHESIS_TOKEN);
           state = LITERAL_STATE;
@@ -143,7 +141,7 @@ class TokenStream {
           state = FORMAT_MODIFIER_STATE;
         } else {
           addValuedToken(Token.KEYWORD, buf, tokenList);
-          if (c == RIGHT_PARENTHESIS) {
+          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) {
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 367c0c8..f9103cd 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
@@ -24,14 +24,15 @@ import ch.qos.logback.core.rolling.helper.FileNamePattern;
 public class AlmostAsIsEscapeUtil implements IEscapeUtil {
 
   /**
-   * Do not perform any character escaping, except for '%'.
+   * Do not perform any character escaping, except for '%', and ')'.
    * 
    * <p>
    * Here is the rationale. First, filename patterns do not include escape
    * combinations such as \r or \n. Moreover, characters which have special
-   * meaning in logback parsers, such as '(', ')', '{', or '}' cannot be part of
-   * file names (so me thinks). Thus, the only character that needs escaping is
-   * '%'.
+   * meaning in logback parsers, such as '{', or '}' cannot be part of file
+   * names (so me thinks). The left parenthesis character has special meaning
+   * only if it is preceded by %. Thus, the only characters that needs escaping
+   * are '%' and ')'.
    * 
    * <p>
    * Note that this method assumes that it is called after the escape character
@@ -40,10 +41,11 @@ public class AlmostAsIsEscapeUtil implements IEscapeUtil {
   public void escape(String escapeChars, StringBuffer buf, char next,
       int pointer) {
 
-    if (next == CoreConstants.PERCENT_CHAR) {
-      buf.append(CoreConstants.PERCENT_CHAR);
+    if (next == CoreConstants.PERCENT_CHAR
+        || next == CoreConstants.RIGHT_PARENTHESIS_CHAR) {
+      buf.append(next);
     } else {
-      // restitute the escape char (because it was consumed 
+      // restitute the escape char (because it was consumed
       // before this method was called).
       buf.append("\\");
       // restitute the next character
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
index 19be55a..0e99868 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
@@ -21,10 +21,11 @@ import ch.qos.logback.core.rolling.helper.DefaultArchiveRemover;
 /**
  * 
  * @author Ceki G&uuml;lc&uuml;
- *
+ * 
  * @param <E>
  */
-public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
+public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends
+    TimeBasedFileNamingAndTriggeringPolicyBase<E> {
 
   @Override
   public void start() {
@@ -33,7 +34,7 @@ public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedF
     archiveRemover.setContext(context);
     started = true;
   }
-  
+
   public boolean isTriggeringEvent(File activeFile, final E event) {
     long time = getCurrentTime();
     if (time >= nextCheck) {
@@ -47,4 +48,9 @@ public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedF
       return false;
     }
   }
+
+  @Override
+  public String toString() {
+    return "c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy";
+  }
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
index cc425e1..88adfe6 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
@@ -58,7 +58,12 @@ public class FileNamePattern extends ContextAwareBase {
 
   void parse() {
     try {
-      Parser<Object> p = new Parser<Object>(pattern, new AlmostAsIsEscapeUtil());
+      // http://jira.qos.ch/browse/LBCORE-130
+      // we escape ')' for parsing purposes. Note that the original pattern is preserved
+      // because it is shown to the user in status messages. We don't want the escaped version
+      // to leak out.
+      String patternForParsing = escapeRightParantesis(pattern);
+      Parser<Object> p = new Parser<Object>(patternForParsing, new AlmostAsIsEscapeUtil());
       p.setContext(context);
       Node t = p.parse();
       this.headTokenConverter = p.compile(t, CONVERTER_MAP);
@@ -68,6 +73,10 @@ public class FileNamePattern extends ContextAwareBase {
     }
   }
 
+  String escapeRightParantesis(String in) {
+    return pattern.replace(")", "\\)");
+  }
+
   public String toString() {
     return pattern;
   }
@@ -145,8 +154,8 @@ public class FileNamePattern extends ContextAwareBase {
   }
 
   /**
-   * Given date, convert this instance to a  regular expression.
-    */
+   * Given date, convert this instance to a regular expression.
+   */
   public String toRegex(Date date) {
     StringBuilder buf = new StringBuilder();
     Converter<Object> p = headTokenConverter;
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
index 93a029d..4b4cdf9 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
@@ -30,6 +30,7 @@ import ch.qos.logback.core.layout.DummyLayout;
 import ch.qos.logback.core.status.Status;
 import ch.qos.logback.core.status.StatusChecker;
 import ch.qos.logback.core.status.StatusManager;
+import ch.qos.logback.core.testUtil.RandomUtil;
 import ch.qos.logback.core.util.CoreTestConstants;
 import ch.qos.logback.core.util.StatusPrinter;
 
@@ -39,6 +40,8 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
   Context context = new ContextBase();
 
   TimeBasedRollingPolicy<Object> tbrp = new TimeBasedRollingPolicy<Object>();
+  int diff = RandomUtil.getPositiveInt();
+  String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
 
   @Before
   public void setUp() throws Exception {
@@ -63,7 +66,8 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
   @Override
   protected Appender<Object> getConfiguredAppender() {
     rfa.setContext(context);
-    tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX+"toto-%d.log");
+    tbrp
+        .setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log");
     tbrp.start();
     rfa.setRollingPolicy(tbrp);
 
@@ -81,7 +85,8 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
     rfa.setBufferedIO(true);
     rfa.setPrudent(true);
 
-    tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX+"toto-%d.log");
+    tbrp
+        .setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log");
     tbrp.start();
     rfa.setRollingPolicy(tbrp);
 
@@ -133,4 +138,17 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
     statusChecker.containsMatch(Status.ERROR,
         "File property must be set before any triggeringPolicy ");
   }
+
+  @Test
+  public void testFileNameWithParenthesis() {
+    // if ')' is not escaped, the test throws
+    // java.lang.IllegalStateException: FileNamePattern [.../program(x86)/toto-%d.log] does not contain a valid DateToken
+    rfa.setContext(context);
+    tbrp
+        .setFileNamePattern(randomOutputDir + "program(x86)/toto-%d.log");
+    tbrp.start();
+    rfa.setRollingPolicy(tbrp);
+    rfa.start();
+    rfa.doAppend("hello");
+  }
 }
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 8dfab6b..4e27d5b 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -42,6 +42,10 @@
     prevents compatibility issues, in particular with recent versions
     of Tomcat whcih store request header names in lower-case.</p>
 
+    <p>Fixed <a
+    href="http://jira.qos.ch/browse/LBCORE-130">LBCORE-130</a>. <code>FileNamePattern</code>
+    no longer treats parenthesis as special.
+    </p>
 
     <hr width="80%" align="center" />
 
diff --git a/logback-site/src/site/pages/templates/footer.js b/logback-site/src/site/pages/templates/footer.js
index 6e51ecc..f97c725 100644
--- a/logback-site/src/site/pages/templates/footer.js
+++ b/logback-site/src/site/pages/templates/footer.js
@@ -10,7 +10,7 @@ document.write('  &nbsp;')
 //document.write('           alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>')
 document.write('   </td>')
 
-document.write('<td valign="top">Copyright &copy; 1999-2009  <a href="http://www.qos.ch/">QOS.ch</a></td>')
+document.write('<td valign="top">Copyright &copy; 1999-2010  <a href="http://www.qos.ch/">QOS.ch</a></td>')
 
 document.write('</tr>')
 document.write('</table>')
diff --git a/logback-site/src/site/pages/templates/left.js b/logback-site/src/site/pages/templates/left.js
index ac41531..b45f09c 100644
--- a/logback-site/src/site/pages/templates/left.js
+++ b/logback-site/src/site/pages/templates/left.js
@@ -1,17 +1,22 @@
 
 document.write('<p class="menu_header">Logback project</p>');
 document.write('<p class="menu"><a href="' + prefix + 'index.html">Introduction</a></p>');
-document.write('<p class="menu"><a href="' + prefix + 'news.html">News</a></p>');
 document.write('<p class="menu"><a href="' + prefix + 'download.html">Download</a></p>');
 document.write('<p class="menu"><a href="' + prefix + 'documentation.html">Documentation</a></p>');
+document.write('<p class="menu"><a href="' + prefix + 'license.html">License</a></p>');
+document.write('<p class="menu"><a href="' + prefix + 'news.html">News</a></p>');
+
+document.write('<p class="menu_header">Support</p>');
 document.write('<p class="menu"><a href="' + prefix + 'mailinglist.html">Mailing Lists</a></p>');
-document.write('<p class="menu"><a href="' + prefix + 'repos.html">Source Repository</a></p>');
 document.write('<p class="menu"><a href="' + prefix + 'bugreport.html">Bug Report</a></p>');
-document.write('<p class="menu"><a href="' + prefix + 'license.html">License</a></p>');
-document.write('<p class="menu"><a href="http://logback.qos.ch/translator/">log4j.properties Translator</a>');
+document.write('<p class="menu"><a href="' + prefix + 'repos.html">Source Repository</a></p>');
+
 document.write('<p class="menu"><a href="http://www.qos.ch/shop/products/professionalSupport">Support offerings</a>');
 document.write('<p class="menu"><a href="http://www.qos.ch/shop/products/training">Training</a>');
 
+document.write('<p class="menu_header">Online Tools</p>');
+document.write('<p class="menu"><a href="http://logback.qos.ch/translator/">log4j.properties Translator</a>');
+
 document.write('</p>');
 
 

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

Summary of changes:
 .../java/ch/qos/logback/core/CoreConstants.java    |    3 +-
 .../logback/core/pattern/parser/TokenStream.java   |   10 +++-----
 .../core/pattern/util/AlmostAsIsEscapeUtil.java    |   16 ++++++++------
 ...aultTimeBasedFileNamingAndTriggeringPolicy.java |   12 ++++++++--
 .../core/rolling/helper/FileNamePattern.java       |   15 ++++++++++--
 .../core/rolling/RollingFileAppenderTest.java      |   22 ++++++++++++++++++-
 logback-site/src/site/pages/news.html              |    4 +++
 logback-site/src/site/pages/templates/footer.js    |    2 +-
 logback-site/src/site/pages/templates/left.js      |   13 ++++++++---
 9 files changed, 70 insertions(+), 27 deletions(-)


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


More information about the logback-dev mailing list