Mercurial > hg > orthanc
changeset 4317:a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 23 Nov 2020 12:04:42 +0100 |
parents | e62bd014ae5c |
children | 3c85edacd0ee |
files | OrthancFramework/Sources/Logging.cpp |
diffstat | 1 files changed, 16 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- 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<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; } }