comparison OrthancFramework/Sources/Logging.cpp @ 4292:6dcadbf1a8af

prefixing log messages with their category
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 05 Nov 2020 10:24:05 +0100
parents d7a50b7b8466
children 29729b7eb6ab
comparison
equal deleted inserted replaced
4291:7e05ad57d7a1 4292:6dcadbf1a8af
594 594
595 595
596 static void GetLinePrefix(std::string& prefix, 596 static void GetLinePrefix(std::string& prefix,
597 LogLevel level, 597 LogLevel level,
598 const char* file, 598 const char* file,
599 int line) 599 int line,
600 LogCategory category)
600 { 601 {
601 boost::filesystem::path path(file); 602 boost::filesystem::path path(file);
602 boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); 603 boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
603 boost::posix_time::time_duration duration = now.time_of_day(); 604 boost::posix_time::time_duration duration = now.time_of_day();
604 605
657 static_cast<int>(duration.seconds()), 658 static_cast<int>(duration.seconds()),
658 static_cast<int>(duration.fractional_seconds())); 659 static_cast<int>(duration.fractional_seconds()));
659 660
660 prefix = (std::string(date) + path.filename().string() + ":" + 661 prefix = (std::string(date) + path.filename().string() + ":" +
661 boost::lexical_cast<std::string>(line) + "] "); 662 boost::lexical_cast<std::string>(line) + "] ");
663
664 if (category != LogCategory_GENERIC)
665 {
666 prefix += "(" + std::string(GetCategoryName(category)) + ") ";
667 }
662 } 668 }
663 669
664 670
665 void InitializePluginContext(void* pluginContext) 671 void InitializePluginContext(void* pluginContext)
666 { 672 {
789 // stream is set to "/dev/null" 795 // stream is set to "/dev/null"
790 return; 796 return;
791 } 797 }
792 798
793 std::string prefix; 799 std::string prefix;
794 GetLinePrefix(prefix, level_, file, line); 800 GetLinePrefix(prefix, level_, file, line, category);
795 801
796 { 802 {
797 // We lock the global mutex. The mutex is locked until the 803 // We lock the global mutex. The mutex is locked until the
798 // destructor is called: No change in the output can be done. 804 // destructor is called: No change in the output can be done.
799 lock_.lock(); 805 lock_.lock();