comparison OrthancFramework/Sources/Logging.cpp @ 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 548d77dfb8bc
children 08e3600dcb1b
comparison
equal deleted inserted replaced
4315:e62bd014ae5c 4317:a691916ab535
38 { 38 {
39 static const uint32_t ALL_CATEGORIES_MASK = 0xffffffff; 39 static const uint32_t ALL_CATEGORIES_MASK = 0xffffffff;
40 40
41 static uint32_t infoCategoriesMask_ = 0; 41 static uint32_t infoCategoriesMask_ = 0;
42 static uint32_t traceCategoriesMask_ = 0; 42 static uint32_t traceCategoriesMask_ = 0;
43 static std::string logTargetFolder_; // keep a track of the log folder in case of reset of the context
44 static std::string logTargetFile_; // keep a track of the log file in case of reset of the context
43 45
44 const char* EnumerationToString(LogLevel level) 46 const char* EnumerationToString(LogLevel level)
45 { 47 {
46 switch (level) 48 switch (level)
47 { 49 {
714 loggingStreamsContext_.reset(NULL); 716 loggingStreamsContext_.reset(NULL);
715 } 717 }
716 718
717 void Reset() 719 void Reset()
718 { 720 {
719 // Recover the old logging context 721 if (logTargetFile_.empty() && logTargetFolder_.empty())
720 std::unique_ptr<LoggingStreamsContext> old; 722 {
723 return;
724 }
721 725
722 { 726 {
723 boost::mutex::scoped_lock lock(loggingStreamsMutex_); 727 boost::mutex::scoped_lock lock(loggingStreamsMutex_);
724 if (loggingStreamsContext_.get() == NULL) 728 loggingStreamsContext_.reset(new LoggingStreamsContext);
725 { 729 }
726 return; 730
727 } 731 // Recover the old logging context if any
728 else 732 if (!logTargetFile_.empty())
729 { 733 {
730 #if __cplusplus < 201103L 734 SetTargetFile(logTargetFile_);
731 old.reset(loggingStreamsContext_.release()); 735 }
732 #else 736 else if (!logTargetFolder_.empty())
733 old = std::move(loggingStreamsContext_); 737 {
734 #endif 738 SetTargetFolder(logTargetFolder_);
735
736 // Create a new logging context,
737 loggingStreamsContext_.reset(new LoggingStreamsContext);
738 }
739 }
740
741 if (!old->targetFolder_.empty())
742 {
743 SetTargetFolder(old->targetFolder_);
744 }
745 else if (!old->targetFile_.empty())
746 {
747 SetTargetFile(old->targetFile_);
748 } 739 }
749 } 740 }
750 741
751 742
752 void SetTargetFolder(const std::string& path) 743 void SetTargetFolder(const std::string& path)
760 loggingStreamsContext_->targetFile_.clear(); 751 loggingStreamsContext_->targetFile_.clear();
761 loggingStreamsContext_->targetFolder_ = path; 752 loggingStreamsContext_->targetFolder_ = path;
762 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get(); 753 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get();
763 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get(); 754 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get();
764 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get(); 755 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get();
756 logTargetFolder_ = path;
765 } 757 }
766 } 758 }
767 759
768 760
769 void SetTargetFile(const std::string& path) 761 void SetTargetFile(const std::string& path)
778 loggingStreamsContext_->targetFile_ = path; 770 loggingStreamsContext_->targetFile_ = path;
779 loggingStreamsContext_->targetFolder_.clear(); 771 loggingStreamsContext_->targetFolder_.clear();
780 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get(); 772 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get();
781 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get(); 773 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get();
782 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get(); 774 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get();
775 logTargetFile_ = path;
783 } 776 }
784 } 777 }
785 778
786 779
787 void InternalLogger::Setup(LogCategory category, 780 void InternalLogger::Setup(LogCategory category,