# HG changeset patch # User Sebastien Jodogne # Date 1591434539 -7200 # Node ID 3c19371090c325f6336b545d379497b2c7ab5609 # Parent 02e61695cd8323fddc301c6c30c28ee223bd7e5a removing useless LoggingMemento diff -r 02e61695cd83 -r 3c19371090c3 Core/Logging.cpp --- a/Core/Logging.cpp Sat Jun 06 10:58:36 2020 +0200 +++ b/Core/Logging.cpp Sat Jun 06 11:08:59 2020 +0200 @@ -459,19 +459,6 @@ { } }; - - struct LoggingMementoImpl - { - bool valid_; - bool infoEnabled_; - bool traceEnabled_; - std::string targetFile_; - std::string targetFolder_; - - std::ostream* error_; - std::ostream* warning_; - std::ostream* info_; - }; } @@ -594,59 +581,6 @@ } - LoggingMemento CreateLoggingMemento() - { - LoggingMementoImpl* memento = new LoggingMementoImpl(); - - memento->valid_ = true; - { - boost::mutex::scoped_lock lock(loggingMutex_); - memento->infoEnabled_ = loggingContext_->infoEnabled_; - memento->traceEnabled_ = loggingContext_->traceEnabled_; - memento->targetFile_ = loggingContext_->targetFile_; - memento->targetFolder_ = loggingContext_->targetFolder_; - - memento->error_ = loggingContext_->error_; - memento->warning_ = loggingContext_->warning_; - memento->info_ = loggingContext_->info_; - } - return reinterpret_cast(memento); - } - - void RestoreLoggingMemento(LoggingMemento mementoPtr) - { - LoggingMementoImpl* memento = - reinterpret_cast(mementoPtr); - if (!memento->valid_) - throw std::runtime_error("Memento already used"); - memento->valid_ = false; - std::unique_ptr deleter(memento); - { - boost::mutex::scoped_lock lock(loggingMutex_); - loggingContext_.reset(new LoggingContext); - loggingContext_->error_ = memento->error_; - loggingContext_->warning_ = memento->warning_; - loggingContext_->info_ = memento->info_; - } - EnableInfoLevel(memento->infoEnabled_); - EnableTraceLevel(memento->traceEnabled_); - if (!memento->targetFolder_.empty()) - { - SetTargetFolder(memento->targetFolder_); - } - else if (!memento->targetFile_.empty()) - { - SetTargetFile(memento->targetFile_); - } - } - - void DiscardLoggingMemento(LoggingMemento mementoPtr) - { - LoggingMementoImpl* memento = - reinterpret_cast(mementoPtr); - delete memento; - } - void EnableInfoLevel(bool enabled) { boost::mutex::scoped_lock lock(loggingMutex_); diff -r 02e61695cd83 -r 3c19371090c3 Core/Logging.h --- a/Core/Logging.h Sat Jun 06 10:58:36 2020 +0200 +++ b/Core/Logging.h Sat Jun 06 11:08:59 2020 +0200 @@ -207,40 +207,6 @@ } }; - /** - opaque pointer that represents the state of the logging configuration - */ - typedef void* LoggingMemento; - - /** - Returns an object that contains the logging configuration. - - This function allocates resources that you must dispose of by - using either RestoreLoggingMemento or DiscardLoggingMemento. - - This function is only to be used by tests. - */ - ORTHANC_PUBLIC LoggingMemento CreateLoggingMemento(); - - /** - Restores the logging configuration. The logging system is restored in - the state it was in when the memento object was created through - GetLoggingMemento(). - - After calling this function, the memento object may not be used - again - - This function is only to be used by tests. - */ - ORTHANC_PUBLIC void RestoreLoggingMemento(LoggingMemento memento); - - /** - Call this function if you do not plan on restoring the logging - configuration state that you captured with CreateLoggingMemento - - This function is only to be used by tests. - */ - ORTHANC_PUBLIC void DiscardLoggingMemento(LoggingMemento memento); /** Set custom logging streams for the error, warning and info logs. diff -r 02e61695cd83 -r 3c19371090c3 UnitTestsSources/LoggingTests.cpp --- a/UnitTestsSources/LoggingTests.cpp Sat Jun 06 10:58:36 2020 +0200 +++ b/UnitTestsSources/LoggingTests.cpp Sat Jun 06 11:08:59 2020 +0200 @@ -105,13 +105,14 @@ class LoggingMementoScope { public: - LoggingMementoScope() : memento_(CreateLoggingMemento()) {} + LoggingMementoScope() + { + } + ~LoggingMementoScope() { - RestoreLoggingMemento(memento_); + Orthanc::Logging::Reset(); } - private: - LoggingMemento memento_; }; }