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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Mar 25 09:59:27 UTC 2019


 common/Log.cpp |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

New commits:
commit d14a62db27cdbbd12aa85cf8f023db68c11d1e61
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Sun Mar 24 23:16:29 2019 -0400
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Mar 25 10:59:08 2019 +0100

    wsd: cache the logger instance to avoid costly lookups
    
    Change-Id: Idf9261d46b44afc42a960146886c180e37d8d51f
    Reviewed-on: https://gerrit.libreoffice.org/69641
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/common/Log.cpp b/common/Log.cpp
index 617e26eca..a5f101e93 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -45,11 +45,13 @@ namespace Log
     struct StaticNameHelper
     {
     private:
-        std::atomic<bool> _inited;
+        Poco::Logger* _logger;
         std::string _name;
         std::string _id;
+        std::atomic<bool> _inited;
     public:
         StaticNameHelper() :
+            _logger(nullptr),
             _inited(true)
         {
         }
@@ -67,6 +69,9 @@ namespace Log
         void setName(const std::string& name) { _name = name; }
 
         const std::string& getName() const { return _name; }
+
+        void setLogger(Poco::Logger* logger) { _logger = logger; };
+        Poco::Logger* getLogger() { return _logger; }
     };
     static StaticNameHelper Source;
 
@@ -171,6 +176,7 @@ namespace Log
          * */
         channel->open();
         auto& logger = Poco::Logger::create(Source.getName(), channel, Poco::Message::PRIO_TRACE);
+        Source.setLogger(&logger);
 
         logger.setLevel(logLevel.empty() ? std::string("trace") : logLevel);
 
@@ -193,7 +199,9 @@ namespace Log
 
     Poco::Logger& logger()
     {
-        return Poco::Logger::get(Source.getInited() ? Source.getName() : std::string());
+        Poco::Logger* pLogger = Source.getLogger();
+        return pLogger ? *pLogger
+                       : Poco::Logger::get(Source.getInited() ? Source.getName() : std::string());
     }
 
     void shutdown()


More information about the Libreoffice-commits mailing list