# HG changeset patch # User Sebastien Jodogne # Date 1714135691 -7200 # Node ID addccb1590d29817458040a2f1c4daab011a1f35 # Parent cc4b7b4d5debdffa322ea5ca23ca50e515d945b3 simplifying Orthanc::Logging diff -r cc4b7b4d5deb -r addccb1590d2 OrthancFramework/Sources/Logging.cpp --- a/OrthancFramework/Sources/Logging.cpp Thu Apr 25 17:16:51 2024 +0200 +++ b/OrthancFramework/Sources/Logging.cpp Fri Apr 26 14:48:11 2024 +0200 @@ -870,10 +870,17 @@ } - void InternalLogger::Setup(LogCategory category, - const char* pluginName, - const char* file, - int line) + InternalLogger::InternalLogger(LogLevel level, + LogCategory category, + const char* pluginName, + const char* file, + int line) : + lock_(loggingStreamsMutex_, boost::defer_lock_t()), + level_(level), + stream_(&nullStream_), // By default, logging to "/dev/null" is simulated + category_(category), + file_(file), + line_(line) { if (pluginContext_ != NULL) { @@ -913,7 +920,9 @@ if (loggingStreamsContext_.get() == NULL) { - 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 ? + // Have you called Orthanc::Logging::InitializePluginContext()? + fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine " + "(or did you forgot to initialize it?)\n"); lock_.unlock(); return; } @@ -963,50 +972,6 @@ } - InternalLogger::InternalLogger(LogLevel level, - LogCategory category, - const char* file, - int line) : - lock_(loggingStreamsMutex_, boost::defer_lock_t()), - level_(level), - stream_(&nullStream_), // By default, logging to "/dev/null" is simulated - category_(category), - file_(file), - line_(line) - { - Setup(category, NULL, file, line); - } - - InternalLogger::InternalLogger(LogLevel level, - LogCategory category, - const char* pluginName, - const char* file, - int line) : - lock_(loggingStreamsMutex_, boost::defer_lock_t()), - level_(level), - stream_(&nullStream_), // By default, logging to "/dev/null" is simulated - category_(category), - file_(file), - line_(line) - { - Setup(category, pluginName, file, line); - } - - - - InternalLogger::InternalLogger(LogLevel level, - const char* file, - int line) : - lock_(loggingStreamsMutex_, boost::defer_lock_t()), - level_(level), - stream_(&nullStream_), // By default, logging to "/dev/null" is simulated - category_(LogCategory_GENERIC), - file_(file), - line_(line) - { - Setup(LogCategory_GENERIC, NULL, file, line); - } - InternalLogger::~InternalLogger() { diff -r cc4b7b4d5deb -r addccb1590d2 OrthancFramework/Sources/Logging.h --- a/OrthancFramework/Sources/Logging.h Thu Apr 25 17:16:51 2024 +0200 +++ b/OrthancFramework/Sources/Logging.h Fri Apr 26 14:48:11 2024 +0200 @@ -181,15 +181,22 @@ # define LOG(level) ::Orthanc::Logging::InternalLogger \ (::Orthanc::Logging::LogLevel_ ## level, \ - ::Orthanc::Logging::LogCategory_GENERIC, __ORTHANC_FILE__, __LINE__) + ::Orthanc::Logging::LogCategory_GENERIC, NULL /* no plugin */, \ + __ORTHANC_FILE__, __LINE__) + # define VLOG(unused) ::Orthanc::Logging::InternalLogger \ (::Orthanc::Logging::LogLevel_TRACE, \ - ::Orthanc::Logging::LogCategory_GENERIC, __ORTHANC_FILE__, __LINE__) + ::Orthanc::Logging::LogCategory_GENERIC, NULL /* no plugin */, \ + __ORTHANC_FILE__, __LINE__) + # define CLOG(level, category) ::Orthanc::Logging::InternalLogger \ (::Orthanc::Logging::LogLevel_ ## level, \ - ::Orthanc::Logging::LogCategory_ ## category, __ORTHANC_FILE__, __LINE__) -# define LOG_FROM_PLUGIN(level, category, pluginName, file, line) ::Orthanc::Logging::InternalLogger \ - (level, category, pluginName, file, line) + ::Orthanc::Logging::LogCategory_ ## category, NULL /* no plugin */, \ + __ORTHANC_FILE__, __LINE__) + +# define LOG_FROM_PLUGIN(level, category, pluginName, file, line) \ + ::Orthanc::Logging::InternalLogger(level, category, pluginName, file, line) + #endif @@ -270,28 +277,13 @@ const char* file_; uint32_t line_; - void Setup(LogCategory category, - const char* pluginName, - const char* file, - int line); - public: InternalLogger(LogLevel level, LogCategory category, - const char* file, - int line); - - InternalLogger(LogLevel level, - LogCategory category, const char* pluginName, const char* file, int line); - // For backward binary compatibility with Orthanc Framework <= 1.8.0 - InternalLogger(LogLevel level, - const char* file, - int line); - ~InternalLogger(); template diff -r cc4b7b4d5deb -r addccb1590d2 OrthancServer/Plugins/Engine/PluginsManager.cpp --- a/OrthancServer/Plugins/Engine/PluginsManager.cpp Thu Apr 25 17:16:51 2024 +0200 +++ b/OrthancServer/Plugins/Engine/PluginsManager.cpp Fri Apr 26 14:48:11 2024 +0200 @@ -162,16 +162,16 @@ return OrthancPluginErrorCode_Success; case _OrthancPluginService_LogMessage: - { - const _OrthancPluginLogMessage& m = *reinterpret_cast(params); - // we may convert directly from OrthancPluginLogLevel to LogLevel (and category) because the enum values must be identical - // for Orthanc::Logging to work both in the core and in the plugins - Orthanc::Logging::LogLevel level = static_cast(m.level); - Orthanc::Logging::LogCategory category = static_cast(m.category); + { + const _OrthancPluginLogMessage& m = *reinterpret_cast(params); + // We can convert directly from OrthancPluginLogLevel to LogLevel (and category) because the enum values must be identical + // for Orthanc::Logging to work both in the core and in the plugins + Orthanc::Logging::LogLevel level = static_cast(m.level); + Orthanc::Logging::LogCategory category = static_cast(m.category); - LOG_FROM_PLUGIN(level, category, m.plugin, m.file, m.line) << m.message; - return OrthancPluginErrorCode_Success; - }; + LOG_FROM_PLUGIN(level, category, m.plugin, m.file, m.line) << m.message; + return OrthancPluginErrorCode_Success; + } default: break;