comparison OrthancFramework/Sources/Logging.cpp @ 5571:addccb1590d2

simplifying Orthanc::Logging
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2024 14:48:11 +0200
parents e02cdf358905
children d7eaa568da15
comparison
equal deleted inserted replaced
5570:cc4b7b4d5deb 5571:addccb1590d2
868 logTargetFile_ = path; 868 logTargetFile_ = path;
869 } 869 }
870 } 870 }
871 871
872 872
873 void InternalLogger::Setup(LogCategory category, 873 InternalLogger::InternalLogger(LogLevel level,
874 const char* pluginName, 874 LogCategory category,
875 const char* file, 875 const char* pluginName,
876 int line) 876 const char* file,
877 int line) :
878 lock_(loggingStreamsMutex_, boost::defer_lock_t()),
879 level_(level),
880 stream_(&nullStream_), // By default, logging to "/dev/null" is simulated
881 category_(category),
882 file_(file),
883 line_(line)
877 { 884 {
878 if (pluginContext_ != NULL) 885 if (pluginContext_ != NULL)
879 { 886 {
880 // We are logging using the Orthanc plugin SDK 887 // We are logging using the Orthanc plugin SDK
881 888
911 // destructor is called: No change in the output can be done. 918 // destructor is called: No change in the output can be done.
912 lock_.lock(); 919 lock_.lock();
913 920
914 if (loggingStreamsContext_.get() == NULL) 921 if (loggingStreamsContext_.get() == NULL)
915 { 922 {
916 fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine (or did you forgot to initialize it ?)\n"); // have you called Orthanc::Logging::InitializePluginContext ? 923 // Have you called Orthanc::Logging::InitializePluginContext()?
924 fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine "
925 "(or did you forgot to initialize it?)\n");
917 lock_.unlock(); 926 lock_.unlock();
918 return; 927 return;
919 } 928 }
920 929
921 switch (level_) 930 switch (level_)
961 } 970 }
962 } 971 }
963 } 972 }
964 973
965 974
966 InternalLogger::InternalLogger(LogLevel level,
967 LogCategory category,
968 const char* file,
969 int line) :
970 lock_(loggingStreamsMutex_, boost::defer_lock_t()),
971 level_(level),
972 stream_(&nullStream_), // By default, logging to "/dev/null" is simulated
973 category_(category),
974 file_(file),
975 line_(line)
976 {
977 Setup(category, NULL, file, line);
978 }
979
980 InternalLogger::InternalLogger(LogLevel level,
981 LogCategory category,
982 const char* pluginName,
983 const char* file,
984 int line) :
985 lock_(loggingStreamsMutex_, boost::defer_lock_t()),
986 level_(level),
987 stream_(&nullStream_), // By default, logging to "/dev/null" is simulated
988 category_(category),
989 file_(file),
990 line_(line)
991 {
992 Setup(category, pluginName, file, line);
993 }
994
995
996
997 InternalLogger::InternalLogger(LogLevel level,
998 const char* file,
999 int line) :
1000 lock_(loggingStreamsMutex_, boost::defer_lock_t()),
1001 level_(level),
1002 stream_(&nullStream_), // By default, logging to "/dev/null" is simulated
1003 category_(LogCategory_GENERIC),
1004 file_(file),
1005 line_(line)
1006 {
1007 Setup(LogCategory_GENERIC, NULL, file, line);
1008 }
1009
1010 975
1011 InternalLogger::~InternalLogger() 976 InternalLogger::~InternalLogger()
1012 { 977 {
1013 if (pluginStream_.get() != NULL) 978 if (pluginStream_.get() != NULL)
1014 { 979 {