changeset 4004:9b5ace33a00d

cleaning SetErrorWarnInfoLoggingStreams()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jun 2020 11:14:10 +0200
parents 3c19371090c3
children 7f9909062d9c
files Core/Logging.cpp Core/Logging.h UnitTestsSources/LoggingTests.cpp
diffstat 3 files changed, 30 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Logging.cpp	Sat Jun 06 11:08:59 2020 +0200
+++ b/Core/Logging.cpp	Sat Jun 06 11:14:10 2020 +0200
@@ -841,24 +841,27 @@
       }
     }
 
-    void SetErrorWarnInfoLoggingStreams(std::ostream* errorStream,
-                                        std::ostream* warningStream,
-                                        std::ostream* infoStream)
+    void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream,
+                                        std::ostream& warningStream,
+                                        std::ostream& infoStream)
     {
-      boost::mutex::scoped_lock lock(loggingMutex_);
       std::unique_ptr<LoggingContext> old;
 
+      {
+        boost::mutex::scoped_lock lock(loggingMutex_);
+
 #if __cplusplus < 201103L
-      old.reset(loggingContext_.release());
+        old.reset(loggingContext_.release());
 #else
-      old = std::move(loggingContext_);
+        old = std::move(loggingContext_);
 #endif
       
-      loggingContext_.reset(new LoggingContext);
-      loggingContext_->error_ = errorStream;
-      loggingContext_->warning_ = warningStream;
-      loggingContext_->info_ = infoStream;
-      lock.unlock();
+        loggingContext_.reset(new LoggingContext);
+        loggingContext_->error_ = &errorStream;
+        loggingContext_->warning_ = &warningStream;
+        loggingContext_->info_ = &infoStream;
+      }
+      
       EnableInfoLevel(old->infoEnabled_);
       EnableTraceLevel(old->traceEnabled_);
     }
--- a/Core/Logging.h	Sat Jun 06 11:08:59 2020 +0200
+++ b/Core/Logging.h	Sat Jun 06 11:14:10 2020 +0200
@@ -209,20 +209,21 @@
 
 
     /**
-       Set custom logging streams for the error, warning and info logs.
-       This function may not be called if a log file or folder has been 
-       set beforehand. All three pointers must be valid and cannot be NULL.
-
-       Please ensure the supplied streams remain alive and valid as long as
-       logging calls are performed.
-
-       In order to prevent dangling pointer usage, it is recommended to call
-       Orthanc::Logging::Reset() before the stream objects are destroyed and 
-       the pointers become invalid.
-    */
-    ORTHANC_PUBLIC void SetErrorWarnInfoLoggingStreams(std::ostream* errorStream,
-                                                       std::ostream* warningStream, 
-                                                       std::ostream* infoStream);
+     * Set custom logging streams for the error, warning and info
+     * logs. This function may not be called if a log file or folder
+     * has been set beforehand. All three references must be valid.
+     *
+     * Please ensure the supplied streams remain alive and valid as
+     * long as logging calls are performed. In order to prevent
+     * dangling pointer usage, it is mandatory to call
+     * Orthanc::Logging::Reset() before the stream objects are
+     * destroyed and the references become invalid.
+     *
+     * This function must only be used by unit tests.
+     **/
+    ORTHANC_PUBLIC void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream,
+                                                       std::ostream& warningStream, 
+                                                       std::ostream& infoStream);
 
 #ifdef __EMSCRIPTEN__
     /**
--- a/UnitTestsSources/LoggingTests.cpp	Sat Jun 06 11:08:59 2020 +0200
+++ b/UnitTestsSources/LoggingTests.cpp	Sat Jun 06 11:14:10 2020 +0200
@@ -133,7 +133,7 @@
   FuncStreamBuf<LoggingFunctionFunc> infoStreamBuf(TestInfo);
   std::ostream infoStream(&infoStreamBuf);
 
-  SetErrorWarnInfoLoggingStreams(&errorStream, &warningStream, &infoStream);
+  SetErrorWarnInfoLoggingStreams(errorStream, warningStream, infoStream);
 
   {
     const char* text = "E is the set of all sets that do not contain themselves. Does E contain itself?";
@@ -184,13 +184,3 @@
     ASSERT_STREQ(payload.c_str(), text);
   }
 }
-
-
-
-
-
-
-
-
-
-