[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch master updated. v_1.0.1-17-g8646e9a

Gitbot git-noreply at pixie.qos.ch
Fri Apr 20 17:49:08 CEST 2012


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  8646e9a3a29560176174aed181dbbd93de56c49f (commit)
      from  e864f034eb3a642f785e1bc0a786a60cbce708ea (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=8646e9a3a29560176174aed181dbbd93de56c49f
http://github.com/ceki/logback/commit/8646e9a3a29560176174aed181dbbd93de56c49f

commit 8646e9a3a29560176174aed181dbbd93de56c49f
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Fri Apr 20 17:46:34 2012 +0200

    Refactoring of DatePatternToRegexUtil and SequenceToRegex4SDF, editing in layouts.html

diff --git a/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java b/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
index 279140a..255812a 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
@@ -65,10 +65,10 @@ public class PatternLayout extends PatternLayoutBase<IAccessEvent> {
   public static final Map<String, String> defaultConverterMap = new HashMap<String, String>();
   public static final String HEADER_PREFIX = "#logback.access pattern: ";
 
-  public static String CLF_PATTERN = "%h %l %u %t \"%r\" %s %b";
+  public static String CLF_PATTERN = "%h %l %u [%t] \"%r\" %s %b";
   public static String CLF_PATTERN_NAME = "common";
   public static String CLF_PATTERN_NAME_2 = "clf";
-  public static String COMBINED_PATTERN = "%h %l %u %t \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\"";
+  public static String COMBINED_PATTERN = "%h %l %u [%t] \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\"";
   public static String COMBINED_PATTERN_NAME = "combined";
 
   static {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
index f779888..90a59ab 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
@@ -19,6 +19,7 @@ import java.util.List;
 import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.pattern.DynamicConverter;
 import ch.qos.logback.core.util.CachingDateFormatter;
+import ch.qos.logback.core.util.DatePatternToRegexUtil;
 
 /**
  * Returns a date formatted by SimpleDateFormatter.
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/CharSequenceState.java b/logback-core/src/main/java/ch/qos/logback/core/util/CharSequenceState.java
new file mode 100644
index 0000000..38b206b
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/CharSequenceState.java
@@ -0,0 +1,32 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2012, 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.util;
+
+/**
+ *  Used to keep state about a char sequence.
+ *  @author Ceki Gulcu
+ */
+class CharSequenceState {
+  final char c;
+  int occurrences;
+
+  public CharSequenceState(char c) {
+    this.c = c;
+    this.occurrences = 1;
+  }
+
+  void incrementOccurrences() {
+    occurrences++;
+  }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java b/logback-core/src/main/java/ch/qos/logback/core/util/CharSequenceToRegexMapper.java
similarity index 74%
rename from logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java
rename to logback-core/src/main/java/ch/qos/logback/core/util/CharSequenceToRegexMapper.java
index 4842d1e..961ad4f 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SequenceToRegex4SDF.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/CharSequenceToRegexMapper.java
@@ -11,36 +11,27 @@
  * 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.rolling.helper;
+package ch.qos.logback.core.util;
 
 /**
- * This class supports mapping tokens (set of same character sequences) to
+ * This class supports mapping character sequences to
  * regular expressions as appropriate for SimpleDateFormatter.
  * 
- * @author ceki
+ * @author Ceki
  * 
  */
-class SequenceToRegex4SDF {
-  final char c;
-  int occurrences;
+class CharSequenceToRegexMapper {
 
-  public SequenceToRegex4SDF(char c) {
-    this.c = c;
-    this.occurrences = 1;
-  }
-
-  void inc() {
-    occurrences++;
-  }
-
-  String toRegex() {
-    switch (c) {
+  String toRegex(CharSequenceState css) {
+    final int occurrences = css.occurrences;
+    final char c = css.c;
+    switch (css.c) {
     case 'G':
     case 'z':
       return ".*";
     case 'M':
       if (occurrences >= 3) {
-        return ".*";
+        return ".\\{3,12}";
       } else {
         return number(occurrences);
       }
@@ -82,12 +73,7 @@ class SequenceToRegex4SDF {
     }
   }
 
-  @Override
-  public String toString() {
-    return c + "(" + occurrences + ")";
-  }
-
-  private String number(int occurences) {
+  private String number(int occurrences) {
     return "\\d{" + occurrences + "}";
   }
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/DatePatternToRegexUtil.java
similarity index 58%
rename from logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java
rename to logback-core/src/main/java/ch/qos/logback/core/util/DatePatternToRegexUtil.java
index a8fc939..ad546f7 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegexUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/DatePatternToRegexUtil.java
@@ -11,7 +11,7 @@
  * 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.rolling.helper;
+package ch.qos.logback.core.util;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -20,47 +20,43 @@ import java.util.List;
 /**
  * This class is concerned with computing a regex corresponding to a date
  * pattern (in {@link SimpleDateFormat} format).
- * 
+ *
  * @author Ceki Gülcü
- * 
  */
 public class DatePatternToRegexUtil {
 
   final String datePattern;
-  final int length;
+  final int datePatternLength;
+  final CharSequenceToRegexMapper regexMapper = new CharSequenceToRegexMapper();
 
   DatePatternToRegexUtil(String datePattern) {
     this.datePattern = datePattern;
-    length = datePattern.length();
+    datePatternLength = datePattern.length();
   }
 
   String toRegex() {
-    List<SequenceToRegex4SDF> sequenceList = tokenize();
+    List<CharSequenceState> charSequenceList = tokenize();
     StringBuilder sb = new StringBuilder();
-    for (SequenceToRegex4SDF seq : sequenceList) {
-      sb.append(seq.toRegex());
+    for (CharSequenceState seq : charSequenceList) {
+      sb.append(regexMapper.toRegex(seq));
     }
     return sb.toString();
   }
 
-  private List<SequenceToRegex4SDF> tokenize() {
-    List<SequenceToRegex4SDF> sequenceList = new ArrayList<SequenceToRegex4SDF>();
-    SequenceToRegex4SDF sequence = null;
-    for (int i = 0; i < length; i++) {
+  private List<CharSequenceState> tokenize() {
+    List<CharSequenceState> sequenceList = new ArrayList<CharSequenceState>();
+
+    CharSequenceState lastCharSequenceState = null;
+
+    for (int i = 0; i < datePatternLength; i++) {
       char t = datePattern.charAt(i);
-      if (sequence == null || sequence.c != t) {
-        sequence = addNewSequence(sequenceList, t);
+      if (lastCharSequenceState == null || lastCharSequenceState.c != t) {
+        lastCharSequenceState = new CharSequenceState(t);
+        sequenceList.add(lastCharSequenceState);
       } else {
-        sequence.inc();
+        lastCharSequenceState.incrementOccurrences();
       }
     }
     return sequenceList;
   }
-
-  SequenceToRegex4SDF addNewSequence(List<SequenceToRegex4SDF> sequenceList,
-      char t) {
-    SequenceToRegex4SDF token = new SequenceToRegex4SDF(t);
-    sequenceList.add(token);
-    return token;
-  }
 }
diff --git a/logback-site/src/site/pages/manual/layouts.html b/logback-site/src/site/pages/manual/layouts.html
index b1145d2..dd20da2 100644
--- a/logback-site/src/site/pages/manual/layouts.html
+++ b/logback-site/src/site/pages/manual/layouts.html
@@ -2174,7 +2174,7 @@ public class MySampleConverter extends ClassicConverter {
     </table>
 		
 		<p>Logback access' <code>PatternLayout</code> also recognizes three keywords, which
-		act like shortcuts to a certain pattern.</p>
+		act like shortcuts.</p>
 
     <table  class="bodyTable">
       <tr>
@@ -2183,22 +2183,22 @@ public class MySampleConverter extends ClassicConverter {
       </tr>
       <tr class="a">
         <td><em>common</em> or <em>CLF</em></td>
-        <td><em>%h %l %u %t \"%r\" %s %b</em></td>
+        <td><em>%h %l %u [%t] "%r" %s %b</em></td>
       </tr>
       <tr class="b">
         <td><em>combined</em></td>
-        <td><em>%h %l %u %t \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\"</em></td>
+        <td><em>%h %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"</em></td>
       </tr>
 
     </table>
 
  	
-	 	<p>The <em>common</em> keyword corresponds to the pattern <em>%h %l %u %t \"%r\" %s %b</em>
+	 	<p>The <em>common</em> keyword corresponds to the pattern <em>'%h %l %u [%t] "%r" %s %b'</em>
 	 	which displays client host, remote log name, user, date, requested URL, status code 
 	 	and response's content length</p>
 	 	
-	 	<p>The <em>combined</em> keyword is a shortcut for <em>%h %l %u %t
-	 	\"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\"</em>. This pattern
+	 	<p>The <em>combined</em> keyword is a shortcut for <em>'%h %l %u [%t]
+	 	"%r" %s %b "%i{Referer}" "%i{User-Agent}"'</em>. This pattern
 	 	begins much like the <em>common</em> pattern but also displays two
 	 	request headers, namely referer, and user-agent.</p>
 

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

Summary of changes:
 .../java/ch/qos/logback/access/PatternLayout.java  |    4 +-
 .../core/rolling/helper/DateTokenConverter.java    |    1 +
 ...oadingException.java => CharSequenceState.java} |   19 +++++++--
 .../CharSequenceToRegexMapper.java}                |   34 +++++------------
 .../helper => util}/DatePatternToRegexUtil.java    |   40 +++++++++-----------
 logback-site/src/site/pages/manual/layouts.html    |   12 +++---
 6 files changed, 51 insertions(+), 59 deletions(-)
 copy logback-core/src/main/java/ch/qos/logback/core/util/{DynamicClassLoadingException.java => CharSequenceState.java} (58%)
 rename logback-core/src/main/java/ch/qos/logback/core/{rolling/helper/SequenceToRegex4SDF.java => util/CharSequenceToRegexMapper.java} (74%)
 rename logback-core/src/main/java/ch/qos/logback/core/{rolling/helper => util}/DatePatternToRegexUtil.java (58%)


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


More information about the logback-dev mailing list