You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ts...@apache.org on 2017/04/11 07:38:13 UTC

[1/2] logging-log4cxx git commit: treat "SSSSSS" in SimpleDateFormat as microseconds

Repository: logging-log4cxx
Updated Branches:
  refs/heads/master 86101108b -> 0d359ddc8


treat "SSSSSS" in SimpleDateFormat as microseconds

This patch allows users to choose timestamp precision in a simple
manner.  The SimpleDateFormat pattern "SSS" will be replaced with the
fractional second part of the entry's timestamp with millisecond
precision (as before), and "SSSSSS" with microsecond precision.

Since runs of "S" characters other than 3 or 6 would not render
correctly (without this patch, "s.SSSS" will render 3 seconds, 123
milliseconds as "3.0123"), such patterns are passed through verbatim so
the user can realize there is a problem.

Signed-off-by: Nathaniel W. Turner <na...@houseofnate.net>


Project: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/commit/d1a7d043
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/tree/d1a7d043
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/diff/d1a7d043

Branch: refs/heads/master
Commit: d1a7d043a8248aae7e9318ad671af9e802879378
Parents: 8610110
Author: Nathaniel W. Turner <na...@houseofnate.net>
Authored: Mon Feb 28 01:06:01 2011 -0500
Committer: Nathaniel W. Turner <nt...@exagrid.com>
Committed: Mon Apr 10 17:25:47 2017 -0400

----------------------------------------------------------------------
 src/main/cpp/simpledateformat.cpp | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4cxx/blob/d1a7d043/src/main/cpp/simpledateformat.cpp
----------------------------------------------------------------------
diff --git a/src/main/cpp/simpledateformat.cpp b/src/main/cpp/simpledateformat.cpp
index 3f84f37..3d6bf2b 100644
--- a/src/main/cpp/simpledateformat.cpp
+++ b/src/main/cpp/simpledateformat.cpp
@@ -497,6 +497,21 @@ public:
 
 
 
+class MicrosecondToken : public NumericToken
+{
+public:
+  MicrosecondToken( int width1 ) : NumericToken( width1 )
+  {
+  }
+
+  int getField( const apr_time_exp_t & tm ) const
+  {
+    return tm.tm_usec;
+  }
+};
+
+
+
 class AMPMToken : public PatternToken
 {
 public:
@@ -683,7 +698,21 @@ void SimpleDateFormat::addToken(const logchar spec, const int repeat, const std:
                break;
 
                case 0x53: // 'S'
-                 token = ( new MillisecondToken( repeat ) );
+                 if ( repeat == 3 )
+                 {
+                   token = ( new MillisecondToken( repeat ) );
+                 }
+                 else if ( repeat == 6 )
+                 {
+                   token = ( new MicrosecondToken( repeat ) );
+                 }
+                 else
+                 {
+                   // It would be nice to support patterns with arbitrary
+                   // subsecond precision (like "s.S" or "s.SSSS"), but we
+                   // don't; make sure the user is not misled.
+                   token = ( new LiteralToken( spec, repeat ) );
+                 }
                break;
 
                case 0x7A: // 'z'


[2/2] logging-log4cxx git commit: Merging PR #1 with some additional changes, because the test "cacheddateformattestcase" failed with the former implementation. Defaulting to using MillisecondToken for now again, as was the case before. If anyone thinks

Posted by ts...@apache.org.
Merging PR #1 with some additional changes, because the test
"cacheddateformattestcase" failed with the former implementation.
Defaulting to using MillisecondToken for now again, as was the case
before. If anyone thinks this is an error, one should simply create an
issue. This closes #1.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/commit/0d359ddc
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/tree/0d359ddc
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/diff/0d359ddc

Branch: refs/heads/master
Commit: 0d359ddc8e74ed399478240cb4748b2aaad54acb
Parents: d1a7d04
Author: Thorsten Sch�ning <ts...@am-soft.de>
Authored: Tue Apr 11 09:36:47 2017 +0200
Committer: Thorsten Sch�ning <ts...@am-soft.de>
Committed: Tue Apr 11 09:36:47 2017 +0200

----------------------------------------------------------------------
 src/main/cpp/simpledateformat.cpp | 42 +++++++++++++++-------------------
 1 file changed, 19 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4cxx/blob/0d359ddc/src/main/cpp/simpledateformat.cpp
----------------------------------------------------------------------
diff --git a/src/main/cpp/simpledateformat.cpp b/src/main/cpp/simpledateformat.cpp
index 3d6bf2b..3ddb05c 100644
--- a/src/main/cpp/simpledateformat.cpp
+++ b/src/main/cpp/simpledateformat.cpp
@@ -89,9 +89,9 @@ namespace log4cxx
           virtual void format(LogString& s,
                               const apr_time_exp_t& date,
                               log4cxx::helpers::Pool& p) const = 0;
-                              
+
     protected:
-           
+
            static void incrementMonth(tm& time, apr_time_exp_t& aprtime) {
                time.tm_mon++;
                aprtime.tm_mon++;
@@ -106,12 +106,12 @@ namespace log4cxx
                time.tm_hour += 12;
                aprtime.tm_hour += 12;
            }
-           
-           static void renderFacet(const std::locale* locale, 
-                incrementFunction inc, 
-                char spec, 
-                unsigned int wspec, 
-                const char* aprspec, 
+
+           static void renderFacet(const std::locale* locale,
+                incrementFunction inc,
+                char spec,
+                unsigned int wspec,
+                const char* aprspec,
                 std::vector<LogString>& values) {
                 std::vector<LogString>::iterator valueIter = values.begin();
                 tm time;
@@ -131,7 +131,7 @@ namespace log4cxx
                             start = os.str().length();
                             (*inc)(time, aprtime);
                         }
-                    } else 
+                    } else
 #endif
                     if (HAS_FACET(*locale,  std::time_put<char>)) {
                         const std::time_put<char>& facet = USE_FACET(*locale, std::time_put<char> );
@@ -145,8 +145,8 @@ namespace log4cxx
                         }
                     }
                 }
-#endif          
-                const size_t BUFSIZE = 256; 
+#endif
+                const size_t BUFSIZE = 256;
                 char buf[BUFSIZE];
                 memset(buf, 0, BUFSIZE);
                 apr_size_t retsize = 0;
@@ -160,7 +160,7 @@ namespace log4cxx
                     }
                 }
             }
-                              
+
     private:
           /**
            * Private copy constructor.
@@ -221,7 +221,7 @@ public:
   void format( LogString& s, const apr_time_exp_t & tm, Pool & p ) const
   {
     size_t initialLength = s.length();
-    
+
     StringHelper::toString( getField( tm ), p, s );
     size_t finalLength = s.length();
     if ( initialLength + width > finalLength )
@@ -615,7 +615,7 @@ void SimpleDateFormat::addToken(const logchar spec, const int repeat, const std:
              PatternToken * token = NULL;
              switch ( spec )
              {
-               case 0x47: // 'G' 
+               case 0x47: // 'G'
                  token = ( new EraToken( repeat, locale ) );
                break;
 
@@ -689,20 +689,16 @@ void SimpleDateFormat::addToken(const logchar spec, const int repeat, const std:
                  token = ( new HourToken( repeat, 1 ) );
                break;
 
-               case 0x6D: // 'm' 
+               case 0x6D: // 'm'
                  token = ( new MinuteToken( repeat ) );
                break;
 
-               case 0x73: // 's' 
+               case 0x73: // 's'
                  token = ( new SecondToken( repeat ) );
                break;
 
                case 0x53: // 'S'
-                 if ( repeat == 3 )
-                 {
-                   token = ( new MillisecondToken( repeat ) );
-                 }
-                 else if ( repeat == 6 )
+                 if ( repeat == 6 )
                  {
                    token = ( new MicrosecondToken( repeat ) );
                  }
@@ -710,8 +706,8 @@ void SimpleDateFormat::addToken(const logchar spec, const int repeat, const std:
                  {
                    // It would be nice to support patterns with arbitrary
                    // subsecond precision (like "s.S" or "s.SSSS"), but we
-                   // don't; make sure the user is not misled.
-                   token = ( new LiteralToken( spec, repeat ) );
+                   // don't; so this is a back-compatible default.
+                   token = ( new MillisecondToken( repeat ) );
                  }
                break;