[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/TileCache.cpp loolwsd/Util.cpp loolwsd/Util.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Dec 23 09:23:28 PST 2015


 loolwsd/ChildProcessSession.cpp  |   10 +++------
 loolwsd/LOOLBroker.cpp           |   17 ++++++++--------
 loolwsd/LOOLKit.cpp              |   40 ++++++++++++++++++++++++++-------------
 loolwsd/LOOLSession.cpp          |   14 ++++++++++---
 loolwsd/LOOLWSD.cpp              |   28 ++++++++++++++-------------
 loolwsd/MasterProcessSession.cpp |   19 +++++++++---------
 loolwsd/TileCache.cpp            |    8 ++-----
 loolwsd/Util.cpp                 |   38 +++++++++++++++++++++++++++++++++++--
 loolwsd/Util.hpp                 |   12 +++++++++++
 9 files changed, 127 insertions(+), 59 deletions(-)

New commits:
commit ea0ddcf73862777ba8f846d4e4dba674236211dd
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Dec 20 12:59:26 2015 -0500

    loolwsd: Nominal logger and fixes
    
    Nominal logging interface and a fix to using Poco
    Application from LOOLKit, which is not a Poco App,
    which caused core dump.
    
    Logs now include process name.
    Added logs to strategic places and some cleanups.
    
    Change-Id: Ib7dcc4f1033dddf7c87cd2e786a91f5b482fb312
    Reviewed-on: https://gerrit.libreoffice.org/20906
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index b74138b..dd56da0 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -18,7 +18,6 @@
 #include <Poco/String.h>
 #include <Poco/StringTokenizer.h>
 #include <Poco/URI.h>
-#include <Poco/Util/Application.h>
 
 #include "ChildProcessSession.hpp"
 #include "LOKitHelper.hpp"
@@ -38,7 +37,6 @@ using Poco::Process;
 using Poco::ProcessHandle;
 using Poco::StringTokenizer;
 using Poco::URI;
-using Poco::Util::Application;
 
 Poco::NotificationQueue ChildProcessSession::_callbackQueue;
 Poco::Mutex ChildProcessSession::_mutex;
@@ -67,11 +65,11 @@ ChildProcessSession::~ChildProcessSession()
 
 bool ChildProcessSession::handleInput(const char *buffer, int length)
 {
+    Log::info(_kindString + ",Input," + getAbbreviatedMessage(buffer, length));
+
     std::string firstLine = getFirstLine(buffer, length);
     StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
-    Application::instance().logger().information(Util::logPrefix() + _kindString + ",Input," + getAbbreviatedMessage(buffer, length));
-
     if (tokens[0] == "canceltiles")
     {
         // this command makes sense only on the command queue level, nothing
@@ -363,7 +361,7 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
     if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, aUri.toString().c_str())) == NULL)
     {
         sendTextFrame("error: cmd=load kind=failed");
-        Application::instance().logger().information(Util::logPrefix() + "Failed to load: " + aUri.toString() + ", error is: " + _loKit->pClass->getError(_loKit));
+        Log::error("Failed to load: " + aUri.toString() + ", error is: " + _loKit->pClass->getError(_loKit));
         return false;
     }
 
@@ -435,7 +433,7 @@ bool ChildProcessSession::getStatus(const char* /*buffer*/, int /*length*/)
     StringTokenizer tokens(status, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
     if (!getTokenString(tokens[1], "type", _docType))
     {
-        Application::instance().logger().information(Util::logPrefix() + "failed to get document type from" + status);
+        Log::error("failed to get document type from" + status);
     }
     sendTextFrame(status);
 
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 5a64598..cca628e 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -233,7 +233,7 @@ namespace
             }
             if (setuid(LOOLWSD::uid) != 0)
             {
-                Application::instance().logger().error(std::string("setuid() failed: ") + strerror(errno));
+                Log::error(std::string("setuid() failed: ") + strerror(errno));
             }
         }
 #endif
@@ -368,7 +368,6 @@ public:
     {
         Process::PID nPID;
 
-        //std::cout << Util::logPrefix() << "Broker,Input," <<  aMessage << std::endl;
         StringTokenizer tokens(aMessage, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
         if (tokens[0] == "request" && tokens.count() == 3)
         {
@@ -469,6 +468,7 @@ public:
                     }
                     pStart = aBuffer;
                     pEnd   = aBuffer + nBytes;
+                    std::cout << Util::logPrefix() << "Broker readFIFO [" << std::string(pStart, nBytes) << "]" << std::endl;
                 }
             }
 
@@ -565,6 +565,7 @@ static int createLibreOfficeKit(bool sharePages, std::string loSubPath, Poco::UI
 
         ProcessHandle procChild = Process::launch(executable, args);
         child = procChild.id();
+        std::cout << Util::logPrefix() << "Launched kit process: " << child << std::endl;
 
         if ( ( nFIFOWriter = open(pipe.c_str(), O_WRONLY) ) < 0 )
         {
@@ -582,7 +583,9 @@ static int startupLibreOfficeKit(bool sharePages, int nLOKits,
 {
     Process::PID pId = -1;
 
-    std::cout << Util::logPrefix() << "starting " << nLOKits << " LoKit instaces." << std::endl;
+    std::cout << Util::logPrefix() << "starting " << nLOKits << " LoKit instaces."
+              << " Shared: " << sharePages << ", loSubPath: " << loSubPath
+              << ", child: " << child << std::endl;
     for (int nCntr = nLOKits; nCntr; nCntr--)
     {
         if ( (pId = createLibreOfficeKit(sharePages, loSubPath, child)) < 0)
@@ -592,7 +595,7 @@ static int startupLibreOfficeKit(bool sharePages, int nLOKits,
         }
     }
 
-   return pId;
+    return pId;
 }
 
 // Broker process
@@ -605,6 +608,8 @@ int main(int argc, char** argv)
     std::string loTemplate;
     int _numPreSpawnedChildren = 0;
 
+    Log::initialize("brk");
+
     for (int i = 0; i < argc; ++i)
     {
         char *cmd = argv[i];
@@ -635,9 +640,7 @@ int main(int argc, char** argv)
         }
         else if (strstr(cmd, "--numprespawns=") == cmd)
         {
-            std::cout << "CMD: " << cmd << std::endl;
             eq = strchrnul(cmd, '=');
-            std::cout << "EQ: " << std::string(eq + 1) << std::endl;
             if (*eq)
                 _numPreSpawnedChildren = std::stoi(std::string(++eq));
         }
@@ -697,8 +700,6 @@ int main(int argc, char** argv)
         std::cout << Util::logPrefix() << aError.what() << std::endl;
     }
 
-    std::cout << "In Broker!" << std::endl;
-
     const Poco::UInt64 _childId = Util::rng::getNext();
 
     Path jailPath = Path::forDirectory(childRoot + Path::separator() + std::to_string(_childId));
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index af0b5f6..f20a8dd 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -14,11 +14,11 @@
 #include <sys/prctl.h>
 #include <sys/poll.h>
 #include <sys/syscall.h>
+#include <signal.h>
 
 #include <memory>
 #include <iostream>
 
-#include <Poco/Util/Application.h>
 #include <Poco/Net/WebSocket.h>
 #include <Poco/Net/HTTPClientSession.h>
 #include <Poco/Net/HTTPRequest.h>
@@ -232,15 +232,28 @@ public:
     {
 #ifdef __linux
       if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("queue_handler"), 0, 0, 0) != 0)
-        std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
+        Log::error(std::string("Cannot set thread name :") + strerror(errno));
 #endif
-        while (true)
+        try
         {
-            std::string input = _queue.get();
-            if (input == "eof")
-                break;
-            if (!_session->handleInput(input.c_str(), input.size()))
-                break;
+            while (true)
+            {
+                std::string input = _queue.get();
+                if (input == "eof")
+                    break;
+                if (!_session->handleInput(input.c_str(), input.size()))
+                    break;
+            }
+        }
+        catch(std::exception& ex)
+        {
+            Log::error(std::string("Exception: ") + ex.what());
+            raise(SIGABRT);
+        }
+        catch(...)
+        {
+            Log::error("Unknown Exception.");
+            raise(SIGABRT);
         }
     }
 
@@ -258,6 +271,7 @@ public:
         _childId(childId),
         _threadId(threadId)
     {
+        std::cout << Util::logPrefix() << "New connection in child: " << _childId << ", thread: " << _threadId << std::endl;
     }
 
     void start()
@@ -332,7 +346,6 @@ public:
             queue.put("eof");
             queueHandlerThread.join();
         }
-
         catch (Exception& exc)
         {
             std::cout << Util::logPrefix() + "Exception: " + exc.what() << std::endl;
@@ -345,6 +358,7 @@ public:
 
     ~Connection()
     {
+        std::cout << Util::logPrefix() << "Closing connection in child: " << _childId << ", thread: " << _threadId << std::endl;
         //_thread.stop();
     }
 
@@ -449,7 +463,6 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
                 if ( aChar == '\r' && *pStart == '\n')
                 {
                     pStart++;
-                    //std::cout << Util::logPrefix() << "child receive: " << aMessage << std::endl;
                     StringTokenizer tokens(aMessage, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
                     if (tokens[0] == "search")
@@ -520,10 +533,11 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
             }
         }
 
-
         // Destroy LibreOfficeKit
         loKit->pClass->destroy(loKit);
 
+        std::cout << Util::logPrefix() << "loolkit finished OK!" << std::endl;
+
         pthread_exit(0);
     }
     catch (Exception& exc)
@@ -534,8 +548,6 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
     {
         std::cout << Util::logPrefix() + "Exception: " + exc.what() << std::endl;
     }
-
-    std::cout << Util::logPrefix() << "loolkit finished OK!" << std::endl;
 }
 
 #ifndef LOOLKIT_NO_MAIN
@@ -547,6 +559,8 @@ int main(int argc, char** argv)
     Poco::UInt64 _childId = 0;
     std::string _pipe;
 
+    Log::initialize("kit");
+
     for (int i = 1; i < argc; ++i)
     {
         char *cmd = argv[i];
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index db59e76..b43908c 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -44,7 +44,6 @@
 #include <Poco/ThreadLocal.h>
 #include <Poco/URI.h>
 #include <Poco/URIStreamOpener.h>
-#include <Poco/Util/Application.h>
 #include <Poco/Exception.h>
 #include <Poco/Net/NetException.h>
 #include <Poco/Net/DialogSocket.h>
@@ -77,7 +76,6 @@ using Poco::ThreadLocal;
 using Poco::UInt64;
 using Poco::URI;
 using Poco::URIStreamOpener;
-using Poco::Util::Application;
 using Poco::Exception;
 using Poco::Net::DialogSocket;
 using Poco::Net::SocketAddress;
@@ -107,13 +105,18 @@ LOOLSession::LOOLSession(std::shared_ptr<WebSocket> ws, Kind kind) :
 
 LOOLSession::~LOOLSession()
 {
-    std::cout << Util::logPrefix() << "LOOLSession dtor this=" << this << " " << _kind << std::endl;
+    std::cout << Util::logPrefix() << "loolsession dtor this=" << this << " " << _kind << std::endl;
     if (_ws)
         Util::shutdownWebSocket(*_ws);
 }
 
 void LOOLSession::sendTextFrame(const std::string& text)
 {
+    if (!_ws)
+        Log::error("No socket to send to.");
+    else
+        Log::debug(_kindString + ",Send," + getAbbreviatedMessage(text.c_str(), text.size()));
+
     std::unique_lock<std::mutex> lock(_mutex);
 
     _ws->sendFrame(text.data(), text.size());
@@ -121,6 +124,11 @@ void LOOLSession::sendTextFrame(const std::string& text)
 
 void LOOLSession::sendBinaryFrame(const char *buffer, int length)
 {
+    if (!_ws)
+        Log::error("No socket to send to.");
+    else
+        Log::debug(_kindString + ",Send," + std::to_string(length) + " bytes");
+
     std::unique_lock<std::mutex> lock(_mutex);
 
     if (length > 1000)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 41da9bb..2bb61a1 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -251,25 +251,25 @@ namespace
         caps = cap_get_proc();
         if (caps == NULL)
         {
-            Application::instance().logger().error(Util::logPrefix() + "cap_get_proc() failed: " + strerror(errno));
+            Log::error(std::string("cap_get_proc() failed: ") + strerror(errno));
             exit(1);
         }
 
         if (cap_set_flag(caps, CAP_EFFECTIVE, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1 ||
             cap_set_flag(caps, CAP_PERMITTED, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1)
         {
-            Application::instance().logger().error(Util::logPrefix() +  "cap_set_flag() failed: " + strerror(errno));
+            Log::error(std::string("cap_set_flag() failed: ") + strerror(errno));
             exit(1);
         }
 
         if (cap_set_proc(caps) == -1)
         {
-            Application::instance().logger().error(std::string("cap_set_proc() failed: ") + strerror(errno));
+            Log::error(std::string("cap_set_proc() failed: ") + strerror(errno));
             exit(1);
         }
 
         char *capText = cap_to_text(caps, NULL);
-        Application::instance().logger().information(Util::logPrefix() + "Capabilities now: " + capText);
+        Log::info(std::string("Capabilities now: ") + capText);
         cap_free(capText);
 
         cap_free(caps);
@@ -283,7 +283,7 @@ namespace
             // to do chroot().
             if (setuid(getuid()) != 0)
             {
-                Application::instance().logger().error(std::string("setuid() failed: ") + strerror(errno));
+                Log::error(std::string("setuid() failed: ") + strerror(errno));
             }
         }
 #if ENABLE_DEBUG
@@ -307,7 +307,7 @@ namespace
             }
             if (setuid(LOOLWSD::uid) != 0)
             {
-                Application::instance().logger().error(std::string("setuid() failed: ") + strerror(errno));
+                Log::error(std::string("setuid() failed: ") + strerror(errno));
             }
         }
 #endif
@@ -608,7 +608,7 @@ public:
             }
             catch (WebSocketException& exc)
             {
-                Application::instance().logger().error(Util::logPrefix() + "RequestHandler::handleRequest(), WebSocketException: " + exc.message());
+                Log::error("RequestHandler::handleRequest(), WebSocketException: " + exc.message());
                 switch (exc.code())
                 {
                 case WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
@@ -626,7 +626,7 @@ public:
         }
         catch (IOException& exc)
         {
-            Application::instance().logger().error(Util::logPrefix() + "IOException: " + exc.message());
+            Log::error("IOException: " + exc.message());
         }
     }
 };
@@ -651,7 +651,7 @@ public:
             line += " / " + it->first + ": " + it->second;
         }
 
-        Application::instance().logger().information(line);
+        Log::info(line);
         return new RequestHandler();
     }
 };
@@ -688,7 +688,7 @@ public:
         }
         catch (WebSocketException& exc)
         {
-            Application::instance().logger().error(Util::logPrefix() + "TestOutput::run(), WebSocketException: " + exc.message());
+            Log::error("TestOutput::run(), WebSocketException: " + exc.message());
             _ws.close();
         }
     }
@@ -1223,7 +1223,7 @@ int LOOLWSD::createBroker()
 
     const auto msg = Util::logPrefix() + "Launching broker: " + executable + " "
                    + Poco::cat(std::string(" "), args.begin(), args.end());
-    Application::instance().logger().information(msg);
+    Log::info(msg);
 
     ProcessHandle child = Process::launch(executable, args);
 
@@ -1255,6 +1255,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     setSignals(false);
 #endif
 
+    Log::initialize("brk");
+
     if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
     {
         std::cout << Util::logPrefix() << "Unable to access " << cache <<
@@ -1394,14 +1396,14 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     // Terminate child processes
     for (auto i : MasterProcessSession::_childProcesses)
     {
-        logger().information(Util::logPrefix() + "Requesting child process " + std::to_string(i.first) + " to terminate");
+        Log::info("Requesting child process " + std::to_string(i.first) + " to terminate");
         Process::requestTermination(i.first);
     }
 
     // wait broker process finish
     waitpid(-1, &status, WUNTRACED);
 
-    std::cout << Util::logPrefix() << "loolwsd finished OK!" << std::endl;
+    Log::info("loolwsd finished OK!");
     return Application::EXIT_OK;
 }
 
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 513e200..2428b82 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -16,7 +16,6 @@
 #include <Poco/Random.h>
 #include <Poco/URI.h>
 #include <Poco/URIStreamOpener.h>
-#include <Poco/Util/Application.h>
 
 #include "LOOLProtocol.hpp"
 #include "LOOLSession.hpp"
@@ -42,7 +41,6 @@ using Poco::StringTokenizer;
 using Poco::Thread;
 using Poco::UInt64;
 using Poco::URI;
-using Poco::Util::Application;
 
 std::map<Process::PID, UInt64> MasterProcessSession::_childProcesses;
 
@@ -73,7 +71,7 @@ MasterProcessSession::~MasterProcessSession()
 
 bool MasterProcessSession::handleInput(const char *buffer, int length)
 {
-    Application::instance().logger().information(Util::logPrefix() + _kindString + ",Input," + getAbbreviatedMessage(buffer, length));
+    Log::info(_kindString + ",Recv," + getAbbreviatedMessage(buffer, length));
 
     std::string firstLine = getFirstLine(buffer, length);
     StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
@@ -609,7 +607,7 @@ void MasterProcessSession::dispatchChild()
         }
         catch (Exception& exc)
         {
-            Application::instance().logger().error( Util::logPrefix() +
+            Log::error(
                 "createDirectories(\"" + aDstPath.toString() + "\") failed: " + exc.displayText() );
 
         }
@@ -620,11 +618,11 @@ void MasterProcessSession::dispatchChild()
             aToCleanup.remove();
 
 #ifdef __linux
-        Application::instance().logger().information(Util::logPrefix() + "Linking " + aSrcFile.toString() + " to " + aDstFile.toString());
+        Log::info("Linking " + aSrcFile.toString() + " to " + aDstFile.toString());
         if (!File(aDstFile).exists() && link(aSrcFile.toString().c_str(), aDstFile.toString().c_str()) == -1)
         {
             // Failed
-            Application::instance().logger().error( Util::logPrefix() +
+            Log::error(
                 "link(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + strerror(errno) );
         }
 #endif
@@ -634,13 +632,13 @@ void MasterProcessSession::dispatchChild()
             //fallback
             if (!File(aDstFile).exists())
             {
-                Application::instance().logger().information(Util::logPrefix() + "Copying " + aSrcFile.toString() + " to " + aDstFile.toString());
+                Log::info(Util::logPrefix() + "Copying " + aSrcFile.toString() + " to " + aDstFile.toString());
                 File(aSrcFile).copyTo(aDstFile.toString());
             }
         }
         catch (Exception& exc)
         {
-            Application::instance().logger().error( Util::logPrefix() +
+            Log::error(
                 "copyTo(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + exc.displayText());
         }
     }
@@ -654,10 +652,13 @@ void MasterProcessSession::dispatchChild()
 
 void MasterProcessSession::forwardToPeer(const char *buffer, int length)
 {
-    Application::instance().logger().information(Util::logPrefix() + _kindString + ",forwardToPeer," + getAbbreviatedMessage(buffer, length));
+    Log::info(_kindString + ",forwardToPeer," + getAbbreviatedMessage(buffer, length));
     auto peer = _peer.lock();
     if (!peer)
+    {
+        Log::error("no peer to forward to");
         return;
+    }
     peer->sendBinaryFrame(buffer, length);
 }
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 3bd5939..56641c1 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -27,7 +27,6 @@
 #include <Poco/StringTokenizer.h>
 #include <Poco/Timestamp.h>
 #include <Poco/URI.h>
-#include <Poco/Util/Application.h>
 
 #include "LOOLWSD.hpp"
 #include "LOOLProtocol.hpp"
@@ -42,7 +41,6 @@ using Poco::StringTokenizer;
 using Poco::SyntaxException;
 using Poco::Timestamp;
 using Poco::URI;
-using Poco::Util::Application;
 
 using namespace LOOLProtocol;
 
@@ -384,7 +382,7 @@ void TileCache::setup(const std::string& timestamp)
         Timestamp::TimeVal lastTimeVal;
         std::istringstream(timestamp) >> lastTimeVal;
         lastModified = lastTimeVal;
-        Application::instance().logger().information(Util::logPrefix() + "Timestamp provided externally: " + timestamp);
+        Log::info("Timestamp provided externally: " + timestamp);
 
         cleanEverything = (getLastModified() < Timestamp(lastModified));
     }
@@ -401,7 +399,7 @@ void TileCache::setup(const std::string& timestamp)
         {
             // document changed externally, clean up everything
             cacheDir.remove(true);
-            Application::instance().logger().information(Util::logPrefix() + "Completely cleared cache: " + toplevelCacheDirName());
+            Log::info("Completely cleared cache: " + toplevelCacheDirName());
         }
         else
         {
@@ -410,7 +408,7 @@ void TileCache::setup(const std::string& timestamp)
             if (editingCacheDir.exists())
             {
                 editingCacheDir.remove(true);
-                Application::instance().logger().information(Util::logPrefix() + "Cleared the editing cache: " + cacheDirName(true));
+                Log::info("Cleared the editing cache: " + cacheDirName(true));
             }
         }
     }
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 4ce1cd0..87dd14a 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -69,6 +69,38 @@ namespace rng
 }
 }
 
+namespace Log
+{
+    static std::string binname;
+
+    void initialize(const std::string& name)
+    {
+        binname = name;
+        auto& logger = Poco::Logger::get(name);
+        logger.information("Initializing " + name);
+    }
+
+    Poco::Logger& logger()
+    {
+        return Poco::Logger::get(binname);
+    }
+
+    void debug(const std::string& msg)
+    {
+        return logger().debug(Util::logPrefix() + msg);
+    }
+
+    void info(const std::string& msg)
+    {
+        logger().information(Util::logPrefix() + msg);
+    }
+
+    void error(const std::string& msg)
+    {
+        return logger().error(Util::logPrefix() + msg);
+    }
+}
+
 namespace Util
 {
     static const Poco::Int64 epochStart = Poco::Timestamp().epochMicroseconds();
@@ -86,8 +118,10 @@ namespace Util
         usec %= (one_s);
 
         std::ostringstream stream;
-        stream << Poco::Process::id() << "," << std::setw(2) << std::setfill('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 << ",";
+        stream << Log::binname << ',' << Poco::Process::id() << ',' << std::setw(2) << std::setfill('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
+               << ',';
 
         return stream.str();
     }
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 8db7df3..8b1babf 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -13,6 +13,7 @@
 #include <string>
 
 #include <Poco/Net/WebSocket.h>
+#include <Poco/Logger.h>
 
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -44,6 +45,17 @@ namespace Util
     ssize_t readMessage(int nPipe, char* pBuffer, ssize_t nSize);
 };
 
+//TODO: Move to own file.
+namespace Log
+{
+    void initialize(const std::string& name);
+    Poco::Logger& logger();
+
+    void debug(const std::string& msg);
+    void info(const std::string& msg);
+    void error(const std::string& msg);
+}
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list