# HG changeset patch # User Alain Mazy # Date 1606129482 -3600 # Node ID a691916ab535d44ee073e9a5cf98c25bababa502 # Parent e62bd014ae5c396e5f5c011a260bd789cf4ca12a fix for 'logs are not stored in log files anymore after a /tools/reset' diff -r e62bd014ae5c -r a691916ab535 OrthancFramework/Sources/Logging.cpp --- a/OrthancFramework/Sources/Logging.cpp Tue Nov 17 11:16:22 2020 +0100 +++ b/OrthancFramework/Sources/Logging.cpp Mon Nov 23 12:04:42 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 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; } }