# HG changeset patch # User Sebastien Jodogne # Date 1591434850 -7200 # Node ID 9b5ace33a00dcaa0a0465860a48bc926e71e008e # Parent 3c19371090c325f6336b545d379497b2c7ab5609 cleaning SetErrorWarnInfoLoggingStreams() diff -r 3c19371090c3 -r 9b5ace33a00d Core/Logging.cpp --- 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 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_); } diff -r 3c19371090c3 -r 9b5ace33a00d Core/Logging.h --- 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__ /** diff -r 3c19371090c3 -r 9b5ace33a00d UnitTestsSources/LoggingTests.cpp --- 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 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); } } - - - - - - - - - -