logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grobme...@apache.org
Subject svn commit: r1481783 - in /logging/log4j/trunk/src: changes/changes.xml main/java/org/apache/log4j/pattern/FormattingInfo.java main/java/org/apache/log4j/pattern/PatternParser.java
Date Mon, 13 May 2013 10:40:20 GMT
Author: grobmeier
Date: Mon May 13 10:40:20 2013
New Revision: 1481783

URL: http://svn.apache.org/r1481783
Log:
merged truncate feature from extras to trunk

Modified:
    logging/log4j/trunk/src/changes/changes.xml
    logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/FormattingInfo.java
    logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/PatternParser.java

Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=1481783&r1=1481782&r2=1481783&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Mon May 13 10:40:20 2013
@@ -21,6 +21,7 @@
   </properties>
   <body>
     <release version="1.2.18" date="2012-??-??" description="Maintenance release">
   
+       <action action="update" dev="grobmeier">Merged truncate feature to FormattingInfo
from extras</action>
        <action issue="54845" action="fix" dev="ggregory" due-to="Robert Balent">Typo
in log4j 1.2 manual</action>
        <action issue="53299" action="update" dev="grobmeier">Simplify log4j build</action>
        <action issue="44370" action="fix" dev="grobmeier">MANIFEST.MF broken in log4j-1.2.15.jar</action>

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/FormattingInfo.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/FormattingInfo.java?rev=1481783&r1=1481782&r2=1481783&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/FormattingInfo.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/FormattingInfo.java Mon May
13 10:40:20 2013
@@ -57,16 +57,45 @@ public final class FormattingInfo {
   private final boolean leftAlign;
 
   /**
+   * Right truncation.
+   * @since 1.2.17
+   */
+  private final boolean rightTruncate;
+
+  /**
    * Creates new instance.
    * @param leftAlign left align if true.
    * @param minLength minimum length.
    * @param maxLength maximum length.
+   * @deprecated since 1.2.17
    */
   public FormattingInfo(
-    final boolean leftAlign, final int minLength, final int maxLength) {
+    final boolean leftAlign, 
+    final int minLength, 
+    final int maxLength) {
     this.leftAlign = leftAlign;
     this.minLength = minLength;
     this.maxLength = maxLength;
+    this.rightTruncate = false;
+  }
+
+  /**
+   * Creates new instance.
+   * @param leftAlign left align if true.
+   * @param rightTruncate right truncate if true.
+   * @param minLength minimum length.
+   * @param maxLength maximum length.
+   * @since 1.2.17
+   */
+  public FormattingInfo(
+    final boolean leftAlign, 
+    final boolean rightTruncate,
+    final int minLength, 
+    final int maxLength) {
+    this.leftAlign = leftAlign;
+    this.minLength = minLength;
+    this.maxLength = maxLength;
+    this.rightTruncate = rightTruncate;
   }
 
   /**
@@ -86,6 +115,15 @@ public final class FormattingInfo {
   }
 
   /**
+   * Determine if right truncated.
+   * @return true if right truncated.
+   * @since 1.2.17
+   */
+  public boolean isRightTruncated() {
+    return rightTruncate;
+  }
+
+  /**
    * Get minimum length.
    * @return minimum length.
    */
@@ -111,7 +149,11 @@ public final class FormattingInfo {
     final int rawLength = buffer.length() - fieldStart;
 
     if (rawLength > maxLength) {
-      buffer.delete(fieldStart, buffer.length() - maxLength);
+      if(rightTruncate) {
+         buffer.setLength(fieldStart + maxLength);
+      } else {
+         buffer.delete(fieldStart, buffer.length() - maxLength);
+      }
     } else if (rawLength < minLength) {
       if (leftAlign) {
         final int fieldEnd = buffer.length();

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/PatternParser.java?rev=1481783&r1=1481782&r2=1481783&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/PatternParser.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/pattern/PatternParser.java Mon May
13 10:40:20 2013
@@ -304,11 +304,22 @@ public final class PatternParser {
         case '-':
           formattingInfo =
             new FormattingInfo(
-              true, formattingInfo.getMinLength(),
+              true, 
+              formattingInfo.isRightTruncated(),
+              formattingInfo.getMinLength(),
               formattingInfo.getMaxLength());
+          break;
 
+        case '!':
+          formattingInfo =
+            new FormattingInfo(
+              formattingInfo.isLeftAligned(), 
+              true,
+              formattingInfo.getMinLength(),
+              formattingInfo.getMaxLength());
           break;
 
+
         case '.':
           state = DOT_STATE;
 
@@ -319,7 +330,9 @@ public final class PatternParser {
           if ((c >= '0') && (c <= '9')) {
             formattingInfo =
               new FormattingInfo(
-                formattingInfo.isLeftAligned(), c - '0',
+                formattingInfo.isLeftAligned(), 
+                formattingInfo.isRightTruncated(),
+                c - '0',
                 formattingInfo.getMaxLength());
             state = MIN_STATE;
           } else {
@@ -343,6 +356,7 @@ public final class PatternParser {
           formattingInfo =
             new FormattingInfo(
               formattingInfo.isLeftAligned(),
+              formattingInfo.isRightTruncated(),
               (formattingInfo.getMinLength() * 10) + (c - '0'),
               formattingInfo.getMaxLength());
         } else if (c == '.') {
@@ -364,7 +378,9 @@ public final class PatternParser {
         if ((c >= '0') && (c <= '9')) {
           formattingInfo =
             new FormattingInfo(
-              formattingInfo.isLeftAligned(), formattingInfo.getMinLength(),
+              formattingInfo.isLeftAligned(), 
+              formattingInfo.isRightTruncated(),
+              formattingInfo.getMinLength(),
               c - '0');
           state = MAX_STATE;
         } else {
@@ -383,7 +399,9 @@ public final class PatternParser {
         if ((c >= '0') && (c <= '9')) {
           formattingInfo =
             new FormattingInfo(
-              formattingInfo.isLeftAligned(), formattingInfo.getMinLength(),
+              formattingInfo.isLeftAligned(), 
+              formattingInfo.isRightTruncated(),
+              formattingInfo.getMinLength(),
               (formattingInfo.getMaxLength() * 10) + (c - '0'));
         } else {
           i = finalizeConverter(



Mime
View raw message