[Libreoffice-commits] online.git: loolwsd/Util.cpp loolwsd/Util.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jan 14 05:41:36 PST 2016


 loolwsd/Util.cpp |   22 ++++++++++++++--------
 loolwsd/Util.hpp |    9 +++++----
 2 files changed, 19 insertions(+), 12 deletions(-)

New commits:
commit 5d07c460652fa6b7ffbf2ef8bc2a6a3190508e77
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Wed Jan 13 09:34:43 2016 -0500

    loolwsd: logging improvements
    
    Error can supress printing errno and warning can
    be asked to print it by setting a bool argument.
    
    Formatting has been improved for readability.
    
    Change-Id: I93d2808fbff4f6cacc583923905438ada7b8e90e
    Reviewed-on: https://gerrit.libreoffice.org/21471
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index ed8757d..af263f0 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -98,15 +98,15 @@ namespace Log
 
         std::ostringstream stream;
         stream << Log::SourceId << '-' << std::setw(2) << std::setfill('0')
-               << (Poco::Thread::current() ? Poco::Thread::current()->id() : 0) << ','
+               << (Poco::Thread::current() ? Poco::Thread::current()->id() : 0) << ' '
                << std::setw(2) << hours << ':' << std::setw(2) << minutes << ':'
                << std::setw(2) << seconds << "." << std::setw(6) << usec
-               << ", ";
+               << ' ';
 
 #ifdef __linux
         char buf[32]; // we really need only 16
         if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(buf), 0, 0, 0) == 0)
-            stream << '[' << buf << "] ";
+            stream << '[' << std::setw(15) << std::setfill(' ') << std::left << buf << "] ";
 #endif
 
         return stream.str();
@@ -160,14 +160,20 @@ namespace Log
         logger().information(logPrefix() + msg);
     }
 
-    void warn(const std::string& msg)
+    void warn(const std::string& msg, const bool append_errno)
     {
-        logger().warning(logPrefix() + msg);
+        logger().warning(logPrefix() + msg +
+                         (append_errno
+                          ? (std::string(" (errno: ") + strerror(errno) + ").")
+                          : std::string(".")));
     }
 
-    void error(const std::string& msg)
+    void error(const std::string& msg, const bool append_errno)
     {
-        logger().error(logPrefix() + msg + " (" + strerror(errno) + ").");
+        logger().error(logPrefix() + msg +
+                       (append_errno
+                        ? (std::string(" (errno: ") + strerror(errno) + ").")
+                        : std::string(".")));
     }
 }
 
@@ -285,7 +291,7 @@ namespace Util
         }
     }
 
-    std::string signalName(int signo)
+    std::string signalName(const int signo)
     {
         switch (signo)
         {
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 702fe98..9dac84c 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -59,8 +59,6 @@ namespace Util
     // Call WebSocket::shutdown() ignoring Poco::IOException
     void shutdownWebSocket(Poco::Net::WebSocket& ws);
 
-    std::string signalName(int signo);
-
     ssize_t writeFIFO(int nPipe, const char* pBuffer, ssize_t nSize);
 
     ssize_t readFIFO(int nPipe, char* pBuffer, ssize_t nSize);
@@ -90,6 +88,9 @@ namespace Util
         removeFile(path.toString(), recursive);
     }
 
+    /// Returns the name of the signal.
+    std::string signalName(int signo);
+
     /// Trap signals to cleanup and exit the process gracefully.
     void setSignals(bool isIgnored);
 };
@@ -103,8 +104,8 @@ namespace Log
     void trace(const std::string& msg);
     void debug(const std::string& msg);
     void info(const std::string& msg);
-    void warn(const std::string& msg);
-    void error(const std::string& msg);
+    void warn(const std::string& msg, const bool append_errno = false);
+    void error(const std::string& msg, const bool append_errno = true);
 
     // The following is to write streaming logs.
     // Log::info() << "Value: 0x" << std::hex << value


More information about the Libreoffice-commits mailing list