[Libreoffice-commits] online.git: common/Log.cpp

Jan Holesovsky kendy at collabora.com
Fri Jan 13 15:14:37 UTC 2017


 common/Log.cpp |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

New commits:
commit 4416c836d0e1456dc80e27c8fb17a95bd195f87c
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Jan 13 16:09:47 2017 +0100

    Log the time in wall-clock time, instead of since the process start.
    
    Otherwise we are getting completely confused times - various processes start
    at various times, so for one process the epoch start can be eg. 20 minutes
    later than for the other.
    
    Change-Id: I6d87e98682a5fcd0348a584cf66f7ffa5813ca66

diff --git a/common/Log.cpp b/common/Log.cpp
index 380b0ed..8d020fb 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -20,6 +20,7 @@
 #include <unistd.h>
 
 #include <Poco/ConsoleChannel.h>
+#include <Poco/DateTimeFormatter.h>
 #include <Poco/FileChannel.h>
 #include <Poco/FormattingChannel.h>
 #include <Poco/PatternFormatter.h>
@@ -36,8 +37,6 @@ namespace Log
 {
     using namespace Poco;
 
-    static const Poco::Int64 epochStart = Poco::Timestamp().epochMicroseconds();
-
     /// Helper to avoid destruction ordering issues.
     struct StaticNames
     {
@@ -82,15 +81,7 @@ namespace Log
         // FIXME: If running under systemd it is redundant to output timestamps, as those will be
         // attached to messages that the systemd journalling mechanism picks up anyway, won't they?
 
-        Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - epochStart;
-
-        const Poco::Int64 one_s = 1000000;
-        const Poco::Int64 hours = usec / (one_s*60*60);
-        usec %= (one_s * 60 * 60);
-        const Poco::Int64 minutes = usec / (one_s*60);
-        usec %= (one_s * 60);
-        const Poco::Int64 seconds = usec / (one_s);
-        usec %= (one_s);
+        std::string time = DateTimeFormatter::format(Poco::Timestamp(), "%H:%M:%s");
 
         char procName[32]; // we really need only 16
         if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(procName), 0, 0, 0) != 0)
@@ -101,9 +92,9 @@ namespace Log
         const char* appName = (Source.inited ? Source.id.c_str() : "<shutdown>");
         assert(strlen(appName) + 32 + 28 < 1024 - 1);
 
-        snprintf(buffer, 4095, "%s-%.04lu %d:%.2d:%.2d.%.6d [ %s ] %s  ", appName,
+        snprintf(buffer, 4095, "%s-%.04lu %s [ %s ] %s  ", appName,
                  syscall(SYS_gettid),
-                 (int)hours, (int)minutes, (int)seconds, (int)usec,
+                 time.c_str(),
                  procName, level);
     }
 


More information about the Libreoffice-commits mailing list