changeset 4318:3c85edacd0ee

merge
author Alain Mazy <alain@mazy.be>
date Mon, 23 Nov 2020 12:04:59 +0100
parents a691916ab535 (diff) 7dc52763ab1c (current diff)
children 3b8a868616a8 08e3600dcb1b
files
diffstat 1 files changed, 16 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Logging.cpp	Sat Nov 21 10:49:54 2020 +0100
+++ b/OrthancFramework/Sources/Logging.cpp	Mon Nov 23 12:04:59 2020 +0100
@@ -40,6 +40,8 @@
     
     static uint32_t infoCategoriesMask_ = 0;
     static uint32_t traceCategoriesMask_ = 0;
+    static std::string logTargetFolder_;            // keep a track of the log folder in case of reset of the context
+    static std::string logTargetFile_;              // keep a track of the log file in case of reset of the context
     
     const char* EnumerationToString(LogLevel level)
     {
@@ -716,35 +718,24 @@
 
     void Reset()
     {
-      // Recover the old logging context
-      std::unique_ptr<LoggingStreamsContext> old;
+      if (logTargetFile_.empty() && logTargetFolder_.empty())
+      {
+        return;
+      }
 
       {
         boost::mutex::scoped_lock lock(loggingStreamsMutex_);
-        if (loggingStreamsContext_.get() == NULL)
-        {
-          return;
-        }
-        else
-        {
-#if __cplusplus < 201103L
-          old.reset(loggingStreamsContext_.release());
-#else
-          old = std::move(loggingStreamsContext_);
-#endif
+        loggingStreamsContext_.reset(new LoggingStreamsContext);
+      }
 
-          // Create a new logging context, 
-          loggingStreamsContext_.reset(new LoggingStreamsContext);
-        }
+      // Recover the old logging context if any
+      if (!logTargetFile_.empty())
+      {
+        SetTargetFile(logTargetFile_);
       }
-      
-      if (!old->targetFolder_.empty())
+      else if (!logTargetFolder_.empty())
       {
-        SetTargetFolder(old->targetFolder_);
-      }
-      else if (!old->targetFile_.empty())
-      {
-        SetTargetFile(old->targetFile_);
+        SetTargetFolder(logTargetFolder_);
       }
     }
 
@@ -762,6 +753,7 @@
         loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get();
         loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get();
         loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get();
+        logTargetFolder_ = path;
       }
     }
 
@@ -780,6 +772,7 @@
         loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get();
         loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get();
         loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get();
+        logTargetFile_ = path;
       }
     }