changeset 5571:addccb1590d2

simplifying Orthanc::Logging
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2024 14:48:11 +0200
parents cc4b7b4d5deb
children f0dc99bc811c
files OrthancFramework/Sources/Logging.cpp OrthancFramework/Sources/Logging.h OrthancServer/Plugins/Engine/PluginsManager.cpp
diffstat 3 files changed, 35 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- 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()
     {
--- 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 <typename T>
--- 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<const _OrthancPluginLogMessage*>(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<Orthanc::Logging::LogLevel>(m.level);
-          Orthanc::Logging::LogCategory category = static_cast<Orthanc::Logging::LogCategory>(m.category);
+      {
+        const _OrthancPluginLogMessage& m = *reinterpret_cast<const _OrthancPluginLogMessage*>(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<Orthanc::Logging::LogLevel>(m.level);
+        Orthanc::Logging::LogCategory category = static_cast<Orthanc::Logging::LogCategory>(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;