[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-0' - common/Log.cpp

Jan Holesovsky kendy at collabora.com
Fri Jan 13 15:26:17 UTC 2017


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

New commits:
commit 2db8969dcd1e3ad3ac0aaef8cabb4372ef5e1747
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
    Reviewed-on: https://gerrit.libreoffice.org/33052
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    Tested-by: Tor Lillqvist <tml at collabora.com>

diff --git a/common/Log.cpp b/common/Log.cpp
index c263975..df2286d 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -19,6 +19,7 @@
 #include <unistd.h>
 
 #include <Poco/ConsoleChannel.h>
+#include <Poco/DateTimeFormatter.h>
 #include <Poco/FileChannel.h>
 #include <Poco/FormattingChannel.h>
 #include <Poco/PatternFormatter.h>
@@ -35,8 +36,6 @@ namespace Log
 {
     using namespace Poco;
 
-    static const Poco::Int64 epochStart = Poco::Timestamp().epochMicroseconds();
-
     /// Helper to avoid destruction ordering issues.
     struct StaticNames
     {
@@ -81,15 +80,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)
@@ -100,9 +91,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