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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Dec 4 08:07:16 UTC 2018


 common/Log.cpp |   34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

New commits:
commit da8785ed50448d91dd69097ffc0393a5677d9a1b
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Dec 4 09:05:43 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Dec 4 09:06:58 2018 +0100

    Log::StaticNameHelper: make members private
    
    Change-Id: I7c46dc6757b98867c4893ee019b3fd6d903020fc

diff --git a/common/Log.cpp b/common/Log.cpp
index 2136de15a..617e26eca 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -44,17 +44,29 @@ namespace Log
     /// Helper to avoid destruction ordering issues.
     struct StaticNameHelper
     {
-        std::atomic<bool> inited;
-        std::string name;
-        std::string id;
+    private:
+        std::atomic<bool> _inited;
+        std::string _name;
+        std::string _id;
+    public:
         StaticNameHelper() :
-            inited(true)
+            _inited(true)
         {
         }
         ~StaticNameHelper()
         {
-            inited = false;
+            _inited = false;
         }
+
+        bool getInited() const { return _inited; }
+
+        void setId(const std::string& id) { _id = id; }
+
+        const std::string& getId() const { return _id; }
+
+        void setName(const std::string& name) { _name = name; }
+
+        const std::string& getName() const { return _name; }
     };
     static StaticNameHelper Source;
 
@@ -105,7 +117,7 @@ namespace Log
 #endif
         Poco::DateTime time;
         snprintf(buffer, len, "%s-%.05lu %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s  ",
-                    (Source.inited ? Source.id.c_str() : "<shutdown>"),
+                    (Source.getInited() ? Source.getId().c_str() : "<shutdown>"),
                     osTid,
                     time.year(), time.month(), time.day(),
                     time.hour(), time.minute(), time.second(),
@@ -127,14 +139,14 @@ namespace Log
                     const bool logToFile,
                     const std::map<std::string, std::string>& config)
     {
-        Source.name = name;
+        Source.setName(name);
         std::ostringstream oss;
-        oss << Source.name;
+        oss << Source.getName();
 #ifndef MOBILEAPP // Just one process in a mobile app, the pid is uninteresting.
         oss << '-'
             << std::setw(5) << std::setfill('0') << Poco::Process::id();
 #endif
-        Source.id = oss.str();
+        Source.setId(oss.str());
 
         // Configure the logger.
         AutoPtr<Channel> channel;
@@ -158,7 +170,7 @@ namespace Log
          * after chroot can cause file creation inside the jail instead of outside
          * */
         channel->open();
-        auto& logger = Poco::Logger::create(Source.name, channel, Poco::Message::PRIO_TRACE);
+        auto& logger = Poco::Logger::create(Source.getName(), channel, Poco::Message::PRIO_TRACE);
 
         logger.setLevel(logLevel.empty() ? std::string("trace") : logLevel);
 
@@ -181,7 +193,7 @@ namespace Log
 
     Poco::Logger& logger()
     {
-        return Poco::Logger::get(Source.inited ? Source.name : std::string());
+        return Poco::Logger::get(Source.getInited() ? Source.getName() : std::string());
     }
 
     void shutdown()


More information about the Libreoffice-commits mailing list