[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-dev
Subject:    svn commit: r706445 - in /logging/log4j/companions/extras/trunk/src:
From:       carnold () apache ! org
Date:       2008-10-20 22:58:59
Message-ID: 20081020225859.D2377238896D () eris ! apache ! org
[Download RAW message or body]

Author: carnold
Date: Mon Oct 20 15:58:59 2008
New Revision: 706445

URL: http://svn.apache.org/viewvc?rev=706445&view=rev
Log:
Bug 46046: Track changes of default timezone in EnhancedPatternLayout

Modified:
    logging/log4j/companions/extras/trunk/src/changes/changes.xml
    logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java


Modified: logging/log4j/companions/extras/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/changes/changes.xml?rev=706445&r1=706444&r2=706445&view=diff
 ==============================================================================
--- logging/log4j/companions/extras/trunk/src/changes/changes.xml (original)
+++ logging/log4j/companions/extras/trunk/src/changes/changes.xml Mon Oct 20 15:58:59 \
2008 @@ -23,6 +23,7 @@
     <release version="1.1" date="TBD" description="">
        <action action="fix" issue="43312">Mangled source-repository.html</action>
        <action action="fix" issue="44899">Extra NPE error message when using missing \
appender class with DOMConfigurator.</action> +       <action action="fix" \
issue="46046">Track changes of default timezone in EnhancedPatternLayout's %d \
conversion pattern.</action>  </release>
 
 

Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java
                
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/ \
org/apache/log4j/pattern/DatePatternConverter.java?rev=706445&r1=706444&r2=706445&view=diff
 ==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java \
                (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java \
Mon Oct 20 15:58:59 2008 @@ -21,6 +21,9 @@
 import org.apache.log4j.spi.LoggingEvent;
 
 import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
 import java.util.Date;
 import java.util.TimeZone;
 
@@ -63,6 +66,41 @@
    */
   private final CachedDateFormat df;
 
+    /**
+     * This class wraps a DateFormat and forces the time zone to the
+     *   default time zone before each format and parse request.
+     */
+  private class DefaultZoneDateFormat extends DateFormat {
+        /**
+         * Wrapped instance of DateFormat.
+         */
+    private final DateFormat dateFormat;
+
+        /**
+         * Construct new instance.
+         * @param format format, may not be null.
+         */
+    public DefaultZoneDateFormat(final DateFormat format) {
+        dateFormat = format;
+    }
+
+        /**
+         * @{inheritDoc}
+         */
+    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition \
fieldPosition) { +        dateFormat.setTimeZone(TimeZone.getDefault());
+        return dateFormat.format(date, toAppendTo, fieldPosition);
+    }
+
+        /**
+         * @{inheritDoc}
+         */
+    public Date parse(String source, ParsePosition pos) {
+        dateFormat.setTimeZone(TimeZone.getDefault());
+        return dateFormat.parse(source, pos);
+    }
+  }
+  
   /**
    * Private constructor.
    * @param options options, may be null.
@@ -95,7 +133,7 @@
     }
 
     int maximumCacheValidity = 1000;
-    SimpleDateFormat simpleFormat = null;
+    DateFormat simpleFormat = null;
 
     try {
       simpleFormat = new SimpleDateFormat(pattern);
@@ -113,6 +151,8 @@
     if ((options != null) && (options.length > 1)) {
       TimeZone tz = TimeZone.getTimeZone((String) options[1]);
       simpleFormat.setTimeZone(tz);
+    } else {
+      simpleFormat = new DefaultZoneDateFormat(simpleFormat);
     }
 
     df = new CachedDateFormat(simpleFormat, maximumCacheValidity);



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic