[jboss-svn-commits] JBoss Common SVN: r3636 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 4 22:23:21 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-11-04 22:23:20 -0500 (Wed, 04 Nov 2009)
New Revision: 3636

Modified:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java
Log:
Add "%z" time zone conversion character

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java	2009-11-04 16:59:49 UTC (rev 3635)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java	2009-11-05 03:23:20 UTC (rev 3636)
@@ -25,6 +25,7 @@
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 import java.util.ArrayList;
+import java.util.TimeZone;
 
 /**
  * A parser which can translate a log4j-style format string into a series of {@code FormatStep} instances.
@@ -64,6 +65,7 @@
         final long time = System.currentTimeMillis();
         final ArrayList<FormatStep> stepList = new ArrayList<FormatStep>();
         final Matcher matcher = pattern.matcher(formatString);
+        TimeZone timeZone = TimeZone.getDefault();
         while (matcher.find()) {
             final String otherText = matcher.group(1);
             if (otherText != null) {
@@ -90,7 +92,7 @@
                         break;
                     }
                     case 'd': {
-                        stepList.add(Formatters.dateFormatStep(argument, leftJustify, minimumWidth, maximumWidth));
+                        stepList.add(Formatters.dateFormatStep(timeZone, argument, leftJustify, minimumWidth, maximumWidth));
                         break;
                     }
                     case 'F': {
@@ -133,6 +135,10 @@
                         stepList.add(Formatters.mdcFormatStep(argument, leftJustify, minimumWidth, maximumWidth));
                         break;
                     }
+                    case 'z': {
+                        timeZone = TimeZone.getTimeZone(argument);
+                        break;
+                    }
                     case '%': {
                         stepList.add(Formatters.textFormatStep("%"));
                         break;

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java	2009-11-04 16:59:49 UTC (rev 3635)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java	2009-11-05 03:23:20 UTC (rev 3636)
@@ -32,6 +32,7 @@
 import java.security.PrivilegedAction;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.TimeZone;
 import static java.lang.Math.min;
 import static java.lang.Math.max;
 import java.io.PrintWriter;
@@ -219,17 +220,19 @@
     /**
      * Create a format step which emits the date of the log record with the given justificaiton rules.
      *
+     * @param timeZone the time zone to format to
      * @param formatString the date format string
      * @param leftJustify {@code true} to left justify, {@code false} to right justify
      * @param minimumWidth the minimum field width, or 0 for none
      * @param maximumWidth the maximum field width (must be greater than {@code minimumFieldWidth}), or 0 for none
      * @return the format step
      */
-    public static FormatStep dateFormatStep(final String formatString, final boolean leftJustify, final int minimumWidth, final int maximumWidth) {
+    public static FormatStep dateFormatStep(final TimeZone timeZone, final String formatString, final boolean leftJustify, final int minimumWidth, final int maximumWidth) {
         final SimpleDateFormat dateFormatMaster = new SimpleDateFormat(formatString == null ? "yyyy-MM-dd HH:mm:ss,SSS" : formatString);
         return new JustifyingFormatStep(leftJustify, minimumWidth, maximumWidth) {
             public void renderRaw(final StringBuilder builder, final ExtLogRecord record) {
                 final SimpleDateFormat dateFormat = dateFormatMaster;
+                dateFormat.setTimeZone(timeZone);
                 final String formatted;
                 final Date date = new Date(record.getMillis());
                 synchronized (dateFormat) {
@@ -241,6 +244,19 @@
     }
 
     /**
+     * Create a format step which emits the date of the log record with the given justificaiton rules.
+     *
+     * @param formatString the date format string
+     * @param leftJustify {@code true} to left justify, {@code false} to right justify
+     * @param minimumWidth the minimum field width, or 0 for none
+     * @param maximumWidth the maximum field width (must be greater than {@code minimumFieldWidth}), or 0 for none
+     * @return the format step
+     */
+    public static FormatStep dateFormatStep(final String formatString, final boolean leftJustify, final int minimumWidth, final int maximumWidth) {
+        return dateFormatStep(TimeZone.getDefault(), formatString, leftJustify, minimumWidth, maximumWidth);
+    }
+
+    /**
      * Create a format step which emits the source file name with the given justification rules (NOTE: call stack
      * introspection introduces a significant performance penalty).
      *



More information about the jboss-svn-commits mailing list