You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/02/08 06:45:09 UTC

svn commit: r504796 - in /logging/log4j/trunk/tests: input/pattern/patternLayout16.properties src/java/org/apache/log4j/PatternLayoutTestCase.java

Author: carnold
Date: Wed Feb  7 21:45:08 2007
New Revision: 504796

URL: http://svn.apache.org/viewvc?view=rev&rev=504796
Log:
Bug 41565: Timezone specifier reported not to work

Added:
    logging/log4j/trunk/tests/input/pattern/patternLayout16.properties
Modified:
    logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java

Added: logging/log4j/trunk/tests/input/pattern/patternLayout16.properties
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/input/pattern/patternLayout16.properties?view=auto&rev=504796
==============================================================================
--- logging/log4j/trunk/tests/input/pattern/patternLayout16.properties (added)
+++ logging/log4j/trunk/tests/input/pattern/patternLayout16.properties Wed Feb  7 21:45:08 2007
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+log4j.rootCategory=TRACE, testAppender
+log4j.appender.testAppender=org.apache.log4j.FileAppender
+log4j.appender.testAppender.File=output/patternLayout16.log
+log4j.appender.testAppender.Append=false
+log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.testAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}{GMT}Z %d{yyyy-MM-dd HH:mm:ss}{GMT-6}-0600 - %m%n
+
+#  Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.PropertyConfigurator=INFO
+log4j.logger.org.apache.log4j.config.PropertySetter=INFO
+log4j.logger.org.apache.log4j.FileAppender=INFO
+

Modified: logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java?view=diff&rev=504796&r1=504795&r2=504796
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java (original)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java Wed Feb  7 21:45:08 2007
@@ -16,10 +16,7 @@
 
 package org.apache.log4j;
 
-import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 import org.apache.log4j.util.AbsoluteDateAndTimeFilter;
 import org.apache.log4j.util.AbsoluteTimeFilter;
 import org.apache.log4j.util.Compare;
@@ -32,6 +29,12 @@
 import org.apache.log4j.util.SunReflectFilter;
 import org.apache.log4j.util.Transformer;
 
+import java.io.FileReader;
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
 
 public class PatternLayoutTestCase extends TestCase {
   static String TEMP = "output/temp";
@@ -341,6 +344,31 @@
           new JunitTestRunnerFilter()
         });
       assertTrue(Compare.compare(FILTERED, "witness/pattern/patternLayout.15"));
+    }
+
+    /**
+     * Tests explicit UTC time zone in pattern.
+     * @throws Exception
+     */
+    public void test16() throws Exception {
+      final long start = new Date().getTime();
+      PropertyConfigurator.configure("input/pattern/patternLayout16.properties");
+      common();
+      final long end = new Date().getTime();
+      FileReader reader = new FileReader("output/patternLayout16.log");
+      char chars[] = new char[50];
+      reader.read(chars, 0, chars.length);
+      reader.close();
+      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+      format.setTimeZone(TimeZone.getTimeZone("GMT+0"));
+      String utcStr = new String(chars, 0, 19);
+      Date utcDate = format.parse(utcStr, new ParsePosition(0));
+      assertTrue(utcDate.getTime() >= start - 1000 && utcDate.getTime() < end + 1000);
+      String cstStr = new String(chars, 21, 19);
+      format.setTimeZone(TimeZone.getTimeZone("GMT-6"));
+      Date cstDate = format.parse(cstStr, new ParsePosition(0));
+      assertFalse(cstStr.equals(utcStr));
+      assertTrue(cstDate.getTime() >= start - 1000 && cstDate.getTime() < end + 1000);
     }
 
 



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