changeset 5572:f0dc99bc811c

removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2024 15:50:01 +0200
parents addccb1590d2
children 823aae1ea72a
files OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h OrthancServer/Plugins/Samples/ModalityWorklists/CMakeLists.txt OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp OrthancServer/Plugins/Samples/Sanitizer/Plugin.cpp OrthancServer/Plugins/Samples/ServeFolders/CMakeLists.txt OrthancServer/Plugins/Samples/ServeFolders/Plugin.cpp OrthancServer/Plugins/Samples/StorageCommitmentScp/CMakeLists.txt OrthancServer/Plugins/Samples/WebDavFilesystem/CMakeLists.txt OrthancServer/Plugins/Samples/WebDavFilesystem/Plugin.cpp
diffstat 10 files changed, 181 insertions(+), 142 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Apr 26 15:50:01 2024 +0200
@@ -61,6 +61,7 @@
 namespace OrthancPlugins
 {
   static OrthancPluginContext* globalContext_ = NULL;
+  static std::string pluginName_;
 
 
   void SetGlobalContext(OrthancPluginContext* context)
@@ -79,22 +80,19 @@
     }
   }
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4)
-  static const char* pluginName_ = NULL;
-
-  void SetGlobalContext(OrthancPluginContext* context, const char* pluginName)
+
+  void SetGlobalContext(OrthancPluginContext* context,
+                        const char* pluginName)
   {
     SetGlobalContext(context);
     pluginName_ = pluginName;
   }
-#endif
+
 
   void ResetGlobalContext()
   {
     globalContext_ = NULL;
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4)
-    pluginName_ = NULL;
-#endif
+    pluginName_.clear();
   }
 
   bool HasGlobalContext()
@@ -115,6 +113,38 @@
     }
   }
 
+  void LogMessage(OrthancPluginLogLevel level,
+                  const char* file,
+                  uint32_t line,
+                  const std::string& message)
+  {
+    if (HasGlobalContext())
+    {
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4)
+      const char* pluginName = (pluginName_.empty() ? NULL : pluginName_.c_str());
+      OrthancPluginLogMessage(GetGlobalContext(), message.c_str(), pluginName, file, line, OrthancPluginLogCategory_Generic, level);
+#else
+      switch (level)
+      {
+        case OrthancPluginLogLevel_Error:
+          OrthancPluginLogError(GetGlobalContext(), message.c_str());
+          break;
+
+        case OrthancPluginLogLevel_Warning:
+          OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
+          break;
+
+        case OrthancPluginLogLevel_Info:
+          OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
+          break;
+
+        default:
+          ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
+      }
+#endif
+    }
+  }
+
   void LogError(const std::string& message)
   {
     if (HasGlobalContext())
@@ -140,30 +170,6 @@
   }
 
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4)
-  // This file does not have any dependencies on Logging.h, we must call the "native" plugin service
-
-  void _LogMessage(OrthancPluginLogLevel level, const char* file, uint32_t line, const std::string& message)
-  {
-    if (HasGlobalContext())
-    {
-      OrthancPluginLogMessage(GetGlobalContext(), message.c_str(), pluginName_, file, line, OrthancPluginLogCategory_Generic, level);
-    }
-  }
-
-  #define LOG_ERROR(msg) _LogMessage(OrthancPluginLogLevel_Error, __ORTHANC_FILE__, __LINE__, msg);
-  #define LOG_WARNING(msg) _LogMessage(OrthancPluginLogLevel_Warning, __ORTHANC_FILE__, __LINE__, msg);
-  #define LOG_INFO(msg) _LogMessage(OrthancPluginLogLevel_Info, __ORTHANC_FILE__, __LINE__, msg);
-
-#else
-
-  #define LOG_ERROR(msg) LogError(msg);
-  #define LOG_WARNING(msg) LogWarning(msg);
-  #define LOG_INFO(msg) LogInfo(msg);
-
-#endif
-
-
   void MemoryBuffer::Check(OrthancPluginErrorCode code)
   {
     if (code != OrthancPluginErrorCode_Success)
@@ -294,7 +300,7 @@
 
     if (!ReadJson(target, buffer_.data, buffer_.size))
     {
-      LOG_ERROR("Cannot convert some memory buffer to JSON");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
@@ -326,7 +332,7 @@
     explicit PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders)
     {
       for (std::map<std::string, std::string>::const_iterator
-           it = httpHeaders.begin(); it != httpHeaders.end(); ++it)
+             it = httpHeaders.begin(); it != httpHeaders.end(); ++it)
       {
         headersKeys_.push_back(it->first.c_str());
         headersValues_.push_back(it->second.c_str());
@@ -465,7 +471,7 @@
     }
     else
     {
-      LOG_ERROR("Cannot parse JSON: " + std::string(err));
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot parse JSON: " + std::string(err));
       return false;
     }
 #endif
@@ -626,13 +632,13 @@
   {
     if (str_ == NULL)
     {
-      LOG_ERROR("Cannot convert an empty memory buffer to JSON");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot convert an empty memory buffer to JSON");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
     if (!ReadJson(target, str_))
     {
-      LOG_ERROR("Cannot convert some memory buffer to JSON");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
@@ -642,13 +648,13 @@
   {
     if (str_ == NULL)
     {
-      LOG_ERROR("Cannot convert an empty memory buffer to JSON");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot convert an empty memory buffer to JSON");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
     if (!ReadJsonWithoutComments(target, str_))
     {
-      LOG_ERROR("Cannot convert some memory buffer to JSON");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
@@ -686,7 +692,7 @@
 
     if (body.size() > 0xffffffffu)
     {
-      LOG_ERROR("Cannot handle body size > 4GB");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
@@ -706,7 +712,7 @@
 
     if (body.size() > 0xffffffffu)
     {
-      LOG_ERROR("Cannot handle body size > 4GB");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
@@ -756,7 +762,7 @@
 
     if (str.GetContent() == NULL)
     {
-      LOG_ERROR("Cannot access the Orthanc configuration");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot access the Orthanc configuration");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
@@ -764,7 +770,7 @@
 
     if (configuration_.type() != Json::objectValue)
     {
-      LOG_ERROR("Unable to read the Orthanc configuration");
+      ORTHANC_PLUGINS_LOG_ERROR("Unable to read the Orthanc configuration");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
   }
@@ -832,8 +838,8 @@
     {
       if (configuration_[key].type() != Json::objectValue)
       {
-        LOG_ERROR("The configuration section \"" + target.path_ +
-                  "\" is not an associative array as expected");
+        ORTHANC_PLUGINS_LOG_ERROR("The configuration section \"" + target.path_ +
+                                  "\" is not an associative array as expected");
 
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
       }
@@ -855,8 +861,8 @@
 
     if (configuration_[key].type() != Json::stringValue)
     {
-      LOG_ERROR("The configuration option \"" + GetPath(key) +
-                "\" is not a string as expected");
+      ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                "\" is not a string as expected");
 
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
@@ -887,8 +893,8 @@
         return true;
 
       default:
-        LOG_ERROR("The configuration option \"" + GetPath(key) +
-                  "\" is not an integer as expected");
+        ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                  "\" is not an integer as expected");
 
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
@@ -906,8 +912,8 @@
 
     if (tmp < 0)
     {
-      LOG_ERROR("The configuration option \"" + GetPath(key) +
-                "\" is not a positive integer as expected");
+      ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                "\" is not a positive integer as expected");
 
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
@@ -931,8 +937,8 @@
 
     if (configuration_[key].type() != Json::booleanValue)
     {
-      LOG_ERROR("The configuration option \"" + GetPath(key) +
-                "\" is not a Boolean as expected");
+      ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                "\" is not a Boolean as expected");
 
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
@@ -967,8 +973,8 @@
         return true;
 
       default:
-        LOG_ERROR("The configuration option \"" + GetPath(key) +
-                  "\" is not an integer as expected");
+        ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                  "\" is not an integer as expected");
 
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
@@ -1027,8 +1033,8 @@
         break;
     }
 
-    LOG_ERROR("The configuration option \"" + GetPath(key) +
-              "\" is not a list of strings as expected");
+    ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                              "\" is not a list of strings as expected");
 
     ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
   }
@@ -1148,8 +1154,8 @@
 
     if (configuration_[key].type() != Json::objectValue)
     {
-      LOG_ERROR("The configuration option \"" + GetPath(key) +
-                "\" is not an object as expected");
+      ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                "\" is not an object as expected");
 
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
@@ -1166,8 +1172,8 @@
       }
       else
       {
-        LOG_ERROR("The configuration option \"" + GetPath(key) +
-                  "\" is not a dictionary mapping strings to strings");
+        ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
+                                  "\" is not a dictionary mapping strings to strings");
 
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
       }
@@ -1189,7 +1195,7 @@
   {
     if (image_ == NULL)
     {
-      LOG_ERROR("Trying to access a NULL image");
+      ORTHANC_PLUGINS_LOG_ERROR("Trying to access a NULL image");
       ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
@@ -1215,7 +1221,7 @@
 
     if (image_ == NULL)
     {
-      LOG_ERROR("Cannot create an image");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot create an image");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
   }
@@ -1232,7 +1238,7 @@
 
     if (image_ == NULL)
     {
-      LOG_ERROR("Cannot create an image accessor");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot create an image accessor");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
   }
@@ -1246,7 +1252,7 @@
 
     if (image_ == NULL)
     {
-      LOG_ERROR("Cannot uncompress a PNG image");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a PNG image");
       ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
@@ -1259,7 +1265,7 @@
     image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg);
     if (image_ == NULL)
     {
-      LOG_ERROR("Cannot uncompress a JPEG image");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a JPEG image");
       ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
@@ -1273,7 +1279,7 @@
     image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame);
     if (image_ == NULL)
     {
-      LOG_ERROR("Cannot uncompress a DICOM image");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a DICOM image");
       ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
@@ -1687,13 +1693,13 @@
                                    unsigned int minor,
                                    unsigned int revision)
   {
-    LOG_ERROR("Your version of the Orthanc core (" +
-              std::string(GetGlobalContext()->orthancVersion) +
-              ") is too old to run this plugin (version " +
-              boost::lexical_cast<std::string>(major) + "." +
-              boost::lexical_cast<std::string>(minor) + "." +
-              boost::lexical_cast<std::string>(revision) +
-              " is required)");
+    ORTHANC_PLUGINS_LOG_ERROR("Your version of the Orthanc core (" +
+                              std::string(GetGlobalContext()->orthancVersion) +
+                              ") is too old to run this plugin (version " +
+                              boost::lexical_cast<std::string>(major) + "." +
+                              boost::lexical_cast<std::string>(minor) + "." +
+                              boost::lexical_cast<std::string>(revision) +
+                              " is required)");
   }
 
   bool CheckMinimalVersion(const char* version,
@@ -1717,9 +1723,9 @@
     int aa, bb, cc = 0;
     if ((ORTHANC_SCANF(version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 &&
          ORTHANC_SCANF(version, "%4d.%4d", &aa, &bb) != 2) ||
-      aa < 0 ||
-      bb < 0 ||
-      cc < 0)
+        aa < 0 ||
+        bb < 0 ||
+        cc < 0)
     {
       return false;
     }
@@ -1773,7 +1779,7 @@
   {
     if (!HasGlobalContext())
     {
-      LOG_ERROR("Bad Orthanc context in the plugin");
+      ORTHANC_PLUGINS_LOG_ERROR("Bad Orthanc context in the plugin");
       return false;
     }
 
@@ -1810,7 +1816,7 @@
     }
     else
     {
-      LOG_ERROR("Inexistent peer: " + name);
+      ORTHANC_PLUGINS_LOG_ERROR("Inexistent peer: " + name);
       ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
     }
   }
@@ -2094,7 +2100,7 @@
 
     if (body.size() > 0xffffffffu)
     {
-      LOG_ERROR("Cannot handle body size > 4GB");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
@@ -2131,7 +2137,7 @@
 
     if (body.size() > 0xffffffffu)
     {
-      LOG_ERROR("Cannot handle body size > 4GB");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
@@ -2497,7 +2503,7 @@
 
     if (id == NULL)
     {
-      LOG_ERROR("Plugin cannot submit job");
+      ORTHANC_PLUGINS_LOG_ERROR("Plugin cannot submit job");
       OrthancPluginFreeJob(GetGlobalContext(), orthanc);
       ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
     }
@@ -2566,7 +2572,7 @@
           throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()),
                                           status["ErrorDescription"].asString());
 #else
-          LOG_ERROR("Exception while executing the job: " + status["ErrorDescription"].asString());
+          ORTHANC_PLUGINS_LOG_ERROR("Exception while executing the job: " + status["ErrorDescription"].asString());
           ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt());          
 #endif
         }
@@ -2591,7 +2597,7 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
                                       "Expected a JSON object in the body");
 #else
-      LOG_ERROR("Expected a JSON object in the body");
+      ORTHANC_PLUGINS_LOG_ERROR("Expected a JSON object in the body");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
 #endif
     }
@@ -2607,7 +2613,7 @@
                                         "Option \"" + std::string(KEY_SYNCHRONOUS) +
                                         "\" must be Boolean");
 #else
-        LOG_ERROR("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean");
+        ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean");
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
 #endif
       }
@@ -2626,7 +2632,7 @@
                                         "Option \"" + std::string(KEY_ASYNCHRONOUS) +
                                         "\" must be Boolean");
 #else
-        LOG_ERROR("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean");
+        ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean");
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
 #endif
       }
@@ -2647,7 +2653,7 @@
                                         "Option \"" + std::string(KEY_PRIORITY) +
                                         "\" must be an integer");
 #else
-        LOG_ERROR("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer");
+        ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer");
         ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
 #endif
       }
@@ -3168,7 +3174,7 @@
 
     if (body.size() > 0xffffffffu)
     {
-      LOG_ERROR("Cannot handle body size > 4GB");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
       ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
@@ -3313,7 +3319,7 @@
     
     if (!ReadJson(answerBody, body))
     {
-      LOG_ERROR("Cannot convert HTTP answer body to JSON");
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot convert HTTP answer body to JSON");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Fri Apr 26 15:50:01 2024 +0200
@@ -53,16 +53,6 @@
 #endif
 
 
-#if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE)
-#define ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(major, minor, revision)      \
-  (ORTHANC_VERSION_MAJOR > major ||                                     \
-   (ORTHANC_VERSION_MAJOR == major &&                                   \
-    (ORTHANC_VERSION_MINOR > minor ||                                   \
-     (ORTHANC_VERSION_MINOR == minor &&                                 \
-      ORTHANC_VERSION_REVISION >= revision))))
-#endif
-
-
 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0)
 // The "OrthancPluginFindMatcher()" primitive was introduced in Orthanc 1.2.0
 #  define HAS_ORTHANC_PLUGIN_FIND_MATCHER  1
@@ -128,6 +118,31 @@
 #endif
 
 
+// Macro "ORTHANC_PLUGINS_DEPRECATED" tags a function as having been deprecated
+#if (__cplusplus >= 201402L)  // C++14
+#  define ORTHANC_PLUGINS_DEPRECATED(f) [[deprecated]] f
+#elif defined(__GNUC__) || defined(__clang__)
+#  define ORTHANC_PLUGINS_DEPRECATED(f) f __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#  define ORTHANC_PLUGINS_DEPRECATED(f) __declspec(deprecated) f
+#else
+#  define ORTHANC_PLUGINS_DEPRECATED
+#endif
+
+
+#if !defined(__ORTHANC_FILE__)
+#  if defined(_MSC_VER)
+#    pragma message("Warning: Macro __ORTHANC_FILE__ is not defined, this will leak the full path of the source files in the binaries")
+#  else
+#    warning Warning: Macro __ORTHANC_FILE__ is not defined, this will leak the full path of the source files in the binaries
+#  endif
+#  define __ORTHANC_FILE__ __FILE__
+#endif
+
+#define ORTHANC_PLUGINS_LOG_ERROR(msg)   ::OrthancPlugins::LogMessage(OrthancPluginLogLevel_Error, __ORTHANC_FILE__, __LINE__, msg);
+#define ORTHANC_PLUGINS_LOG_WARNING(msg) ::OrthancPlugins::LogMessage(OrthancPluginLogLevel_Warning, __ORTHANC_FILE__, __LINE__, msg);
+#define ORTHANC_PLUGINS_LOG_INFO(msg)    ::OrthancPlugins::LogMessage(OrthancPluginLogLevel_Info, __ORTHANC_FILE__, __LINE__, msg);
+
 
 namespace OrthancPlugins
 {
@@ -137,9 +152,8 @@
 
   void SetGlobalContext(OrthancPluginContext* context);
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4)
-  void SetGlobalContext(OrthancPluginContext* context, const char* pluginName);
-#endif
+  void SetGlobalContext(OrthancPluginContext* context,
+                        const char* pluginName);
 
   void ResetGlobalContext();
 
@@ -641,11 +655,19 @@
   const char* AutodetectMimeType(const std::string& path);
 #endif
 
-  void LogError(const std::string& message);   // From Orthanc 1.12.4, use LOG(ERROR) to display the plugin name, file and line (First set a plugin name in Orthanc::Logging::InitializePluginContext)
+  void LogMessage(OrthancPluginLogLevel level,
+                  const char* file,
+                  uint32_t line,
+                  const std::string& message);
 
-  void LogWarning(const std::string& message); // From Orthanc 1.12.4, use LOG(WARNING) to display the plugin name, file and line (First set a plugin name in Orthanc::Logging::InitializePluginContext)
+  // Use macro ORTHANC_PLUGINS_LOG_ERROR() instead
+  ORTHANC_PLUGINS_DEPRECATED(void LogError(const std::string& message));
 
-  void LogInfo(const std::string& message);    // From Orthanc 1.12.4, use LOG(INFO) to display the plugin name, file and line (First set a plugin name in Orthanc::Logging::InitializePluginContext)
+  // Use macro ORTHANC_PLUGINS_LOG_WARNING() instead
+  ORTHANC_PLUGINS_DEPRECATED(void LogWarning(const std::string& message));
+
+  // Use macro ORTHANC_PLUGINS_LOG_INFO() instead
+  ORTHANC_PLUGINS_DEPRECATED(void LogInfo(const std::string& message));
 
   void ReportMinimalOrthancVersion(unsigned int major,
                                    unsigned int minor,
--- a/OrthancServer/Plugins/Samples/ModalityWorklists/CMakeLists.txt	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/ModalityWorklists/CMakeLists.txt	Fri Apr 26 15:50:01 2024 +0200
@@ -40,6 +40,8 @@
   ${BOOST_SOURCES}
   )
 
+DefineSourceBasenameForTarget(ModalityWorklists)
+
 message("Setting the version of the plugin to ${MODALITY_WORKLISTS_VERSION}")
 add_definitions(
   -DMODALITY_WORKLISTS_VERSION="${MODALITY_WORKLISTS_VERSION}"
--- a/OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp	Fri Apr 26 15:50:01 2024 +0200
@@ -23,7 +23,6 @@
 #define MODALITY_WORKLISTS_NAME "worklists"
 
 #include "../../../../OrthancFramework/Sources/Compatibility.h"
-#include "../../../../OrthancFramework/Sources/Logging.h"
 #include "../Common/OrthancPluginCppWrapper.h"
 
 #include <boost/filesystem.hpp>
@@ -55,7 +54,7 @@
 
     if (code != OrthancPluginErrorCode_Success)
     {
-      LOG(ERROR) << "Error while adding an answer to a worklist request";
+      ORTHANC_PLUGINS_LOG_ERROR("Error while adding an answer to a worklist request");
       ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
     }
 
@@ -78,7 +77,8 @@
   dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short,
                     static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
 
-  LOG(INFO) << "Received worklist query from remote modality " << issuerAet << ":\n" + json.toStyledString();
+  ORTHANC_PLUGINS_LOG_INFO("Received worklist query from remote modality " +
+                           std::string(issuerAet) + ":\n" + json.toStyledString());
 
   if (!filterIssuerAet_)
   {
@@ -185,19 +185,19 @@
                 return OrthancPluginErrorCode_Success;
               }
               
-              LOG(INFO) << "Worklist matched: " << it->path().string();
+              ORTHANC_PLUGINS_LOG_INFO("Worklist matched: " + it->path().string());
               matchedWorklistCount++;
             }
           }
         }
       }
 
-      LOG(INFO) << "Worklist C-Find: parsed " << parsedFilesCount
-                << " files, found " << matchedWorklistCount << " match(es)";
+      ORTHANC_PLUGINS_LOG_INFO("Worklist C-Find: parsed " + boost::lexical_cast<std::string>(parsedFilesCount) +
+                               " files, found " + boost::lexical_cast<std::string>(matchedWorklistCount) + " match(es)");
     }
     catch (fs::filesystem_error&)
     {
-      LOG(ERROR) << "Inexistent folder while scanning for worklists: " << source.string();
+      ORTHANC_PLUGINS_LOG_ERROR("Inexistent folder while scanning for worklists: " + source.string());
       return OrthancPluginErrorCode_DirectoryExpected;
     }
 
@@ -214,7 +214,6 @@
 {
   ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
   {
-    Orthanc::Logging::InitializePluginContext(c, MODALITY_WORKLISTS_NAME);
     OrthancPlugins::SetGlobalContext(c, MODALITY_WORKLISTS_NAME);
 
     /* Check the version of the Orthanc core */
@@ -226,7 +225,7 @@
       return -1;
     }
 
-    LOG(WARNING) << "Sample worklist plugin is initializing";
+    ORTHANC_PLUGINS_LOG_WARNING("Sample worklist plugin is initializing");
     OrthancPluginSetDescription2(c, MODALITY_WORKLISTS_NAME, "Serve DICOM modality worklists from a folder with Orthanc.");
 
     OrthancPlugins::OrthancConfiguration configuration;
@@ -239,12 +238,12 @@
     {
       if (worklists.LookupStringValue(folder_, "Database"))
       {
-        LOG(WARNING) << "The database of worklists will be read from folder: " << folder_;
+        ORTHANC_PLUGINS_LOG_WARNING("The database of worklists will be read from folder: " + folder_);
         OrthancPluginRegisterWorklistCallback(OrthancPlugins::GetGlobalContext(), Callback);
       }
       else
       {
-        LOG(ERROR) << "The configuration option \"Worklists.Database\" must contain a path";
+        ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"Worklists.Database\" must contain a path");
         return -1;
       }
 
@@ -253,7 +252,7 @@
     }
     else
     {
-      LOG(WARNING) << "Worklist server is disabled by the configuration file";
+      ORTHANC_PLUGINS_LOG_WARNING("Worklist server is disabled by the configuration file");
     }
 
     return 0;
@@ -262,7 +261,7 @@
 
   ORTHANC_PLUGINS_API void OrthancPluginFinalize()
   {
-    LOG(WARNING) << "Sample worklist plugin is finalizing";
+    ORTHANC_PLUGINS_LOG_WARNING("Sample worklist plugin is finalizing");
   }
 
 
--- a/OrthancServer/Plugins/Samples/Sanitizer/Plugin.cpp	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/Sanitizer/Plugin.cpp	Fri Apr 26 15:50:01 2024 +0200
@@ -70,7 +70,7 @@
       return -1;
     }
     
-    OrthancPlugins::LogWarning("Sanitizer plugin is initializing");
+    ORTHANC_PLUGINS_LOG_WARNING("Sanitizer plugin is initializing");
     OrthancPlugins::SetDescription(ORTHANC_PLUGIN_NAME, "Sample plugin to sanitize incoming DICOM instances.");
 
     OrthancPluginRegisterReceivedInstanceCallback(c, ReceivedInstanceCallback);
@@ -81,7 +81,7 @@
 
   ORTHANC_PLUGINS_API void OrthancPluginFinalize()
   {
-    OrthancPlugins::LogWarning("Sanitizer plugin is finalizing");
+    ORTHANC_PLUGINS_LOG_WARNING("Sanitizer plugin is finalizing");
     Orthanc::FinalizeFramework();
   }
 
--- a/OrthancServer/Plugins/Samples/ServeFolders/CMakeLists.txt	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/ServeFolders/CMakeLists.txt	Fri Apr 26 15:50:01 2024 +0200
@@ -40,6 +40,8 @@
   ${BOOST_SOURCES}
   )
 
+DefineSourceBasenameForTarget(ServeFolders)
+
 add_definitions(-DHAS_ORTHANC_EXCEPTION=0)
 
 message("Setting the version of the plugin to ${SERVE_FOLDERS_VERSION}")
--- a/OrthancServer/Plugins/Samples/ServeFolders/Plugin.cpp	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/ServeFolders/Plugin.cpp	Fri Apr 26 15:50:01 2024 +0200
@@ -23,7 +23,6 @@
 #define SERVE_FOLDERS_NAME "serve-folders"
 
 #include "../Common/OrthancPluginCppWrapper.h"
-#include "../../../OrthancFramework/Sources/Logging.h"
 
 #include <json/value.h>
 #include <boost/filesystem.hpp>
@@ -95,7 +94,7 @@
   }
   else
   {
-    LOG(WARNING) << "ServeFolders: Unknown MIME type for extension \"" << extension << "\"";
+    ORTHANC_PLUGINS_LOG_WARNING("ServeFolders: Unknown MIME type for extension \"" + extension + "\"");
     return "application/octet-stream";
   }
 }
@@ -110,7 +109,7 @@
   std::map<std::string, std::string>::const_iterator found = folders_.find(uri);
   if (found == folders_.end())
   {
-    LOG(ERROR) << "Unknown URI in plugin server-folders: " << uri;
+    ORTHANC_PLUGINS_LOG_ERROR("Unknown URI in plugin server-folders: " + uri);
     OrthancPluginSendHttpStatusCode(OrthancPlugins::GetGlobalContext(), output, 404);
     return false;
   }
@@ -266,7 +265,7 @@
 {
   if (folders.type() != Json::objectValue)
   {
-    LOG(ERROR) << "The list of folders to be served is badly formatted (must be a JSON object)";
+    ORTHANC_PLUGINS_LOG_ERROR("The list of folders to be served is badly formatted (must be a JSON object)");
     ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
   }
 
@@ -278,8 +277,8 @@
   {
     if (folders[*it].type() != Json::stringValue)
     {
-      LOG(ERROR) << "The folder to be served \"" << *it << 
-                    "\" must be associated with a string value (its mapped URI)";
+      ORTHANC_PLUGINS_LOG_ERROR("The folder to be served \"" + *it + 
+                                "\" must be associated with a string value (its mapped URI)");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
@@ -300,7 +299,7 @@
 
     if (baseUri.empty())
     {
-      LOG(ERROR) << "The URI of a folder to be served cannot be empty";
+      ORTHANC_PLUGINS_LOG_ERROR("The URI of a folder to be served cannot be empty");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
@@ -308,7 +307,7 @@
     const std::string folder = folders[*it].asString();
     if (!boost::filesystem::is_directory(folder))
     {
-      LOG(ERROR) << "Trying to serve an inexistent folder: " + folder;
+      ORTHANC_PLUGINS_LOG_ERROR("Trying to serve an inexistent folder: " + folder);
       ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentFile);
     }
 
@@ -327,7 +326,7 @@
 {
   if (extensions.type() != Json::objectValue)
   {
-    LOG(ERROR) << "The list of extensions is badly formatted (must be a JSON object)";
+    ORTHANC_PLUGINS_LOG_ERROR("The list of extensions is badly formatted (must be a JSON object)");
     ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
   }
 
@@ -338,8 +337,8 @@
   {
     if (extensions[*it].type() != Json::stringValue)
     {
-      LOG(ERROR) << "The file extension \"" << *it << 
-                    "\" must be associated with a string value (its MIME type)";
+      ORTHANC_PLUGINS_LOG_ERROR("The file extension \"" + *it + 
+                                "\" must be associated with a string value (its MIME type)");
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
@@ -357,11 +356,13 @@
 
     if (mime.empty())
     {
-      LOG(WARNING) << "ServeFolders: Removing MIME type for file extension \"." << name << "\"";
+      ORTHANC_PLUGINS_LOG_WARNING("ServeFolders: Removing MIME type for file extension \"." +
+                                  name + "\"");
     }
     else
     {
-      LOG(WARNING) << "ServeFolders: Associating file extension \"." << name << "\" with MIME type \"" << mime << "\"";
+      ORTHANC_PLUGINS_LOG_WARNING("ServeFolders: Associating file extension \"." + name +
+                                  "\" with MIME type \"" + mime + "\"");
     }
   }  
 }
@@ -391,13 +392,16 @@
     if (configuration.LookupBooleanValue(tmp, "AllowCache"))
     {
       allowCache_ = tmp;
-      LOG(WARNING) << "ServeFolders: Requesting the HTTP client to " << (tmp ? "enable" : "disable") << " its caching mechanism";
+      ORTHANC_PLUGINS_LOG_WARNING("ServeFolders: Requesting the HTTP client to " +
+                                  std::string(tmp ? "enable" : "disable") +
+                                  " its caching mechanism");
     }
 
     if (configuration.LookupBooleanValue(tmp, "GenerateETag"))
     {
       generateETag_ = tmp;
-      LOG(WARNING) << "ServeFolders: The computation of an ETag for the served resources is " << (tmp ? "enabled" : "disabled");
+      ORTHANC_PLUGINS_LOG_WARNING("ServeFolders: The computation of an ETag for the served resources is " +
+                                  std::string(tmp ? "enabled" : "disabled"));
     }
 
     OrthancPlugins::OrthancConfiguration extensions;
@@ -407,7 +411,7 @@
 
   if (folders_.empty())
   {
-    LOG(WARNING) << "ServeFolders: Empty configuration file: No additional folder will be served!";
+    ORTHANC_PLUGINS_LOG_WARNING("ServeFolders: Empty configuration file: No additional folder will be served!");
   }
 }
 
@@ -417,7 +421,6 @@
   ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
   {
     OrthancPlugins::SetGlobalContext(context, SERVE_FOLDERS_NAME);
-    Orthanc::Logging::InitializePluginContext(context, SERVE_FOLDERS_NAME);
 
     /* Check the version of the Orthanc core */
     if (OrthancPluginCheckVersion(context) == 0)
@@ -439,7 +442,8 @@
     }
     catch (OrthancPlugins::PluginException& e)
     {
-      LOG(ERROR) << "Error while initializing the ServeFolders plugin: " << e.What(context);
+      ORTHANC_PLUGINS_LOG_ERROR("Error while initializing the ServeFolders plugin: " +
+                                std::string(e.What(context)));
     }
 
     return 0;
--- a/OrthancServer/Plugins/Samples/StorageCommitmentScp/CMakeLists.txt	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/StorageCommitmentScp/CMakeLists.txt	Fri Apr 26 15:50:01 2024 +0200
@@ -40,6 +40,8 @@
   ${BOOST_SOURCES}
   )
 
+DefineSourceBasenameForTarget(StorageCommitmentScp)
+
 message("Setting the version of the plugin to ${PLUGIN_VERSION}")
 add_definitions(
   -DPLUGIN_VERSION="${PLUGIN_VERSION}"
--- a/OrthancServer/Plugins/Samples/WebDavFilesystem/CMakeLists.txt	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/WebDavFilesystem/CMakeLists.txt	Fri Apr 26 15:50:01 2024 +0200
@@ -40,3 +40,5 @@
   ${JSONCPP_SOURCES}
   ${BOOST_SOURCES}
   )
+
+DefineSourceBasenameForTarget(WebDavFilesystem)
--- a/OrthancServer/Plugins/Samples/WebDavFilesystem/Plugin.cpp	Fri Apr 26 14:48:11 2024 +0200
+++ b/OrthancServer/Plugins/Samples/WebDavFilesystem/Plugin.cpp	Fri Apr 26 15:50:01 2024 +0200
@@ -164,7 +164,7 @@
 
     if (content_.find(name) != content_.end())
     {
-      OrthancPlugins::LogError("Already existing: " + name);
+      ORTHANC_PLUGINS_LOG_ERROR("Already existing: " + name);
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadRequest);
     }
     else
@@ -177,7 +177,7 @@
   {
     if (content_.find(name) != content_.end())
     {
-      OrthancPlugins::LogError("Already existing: " + name);
+      ORTHANC_PLUGINS_LOG_ERROR("Already existing: " + name);
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadRequest);
     }
     else
@@ -192,7 +192,7 @@
 
     if (found == content_.end())
     {
-      OrthancPlugins::LogError("Cannot delete inexistent path: " + name);
+      ORTHANC_PLUGINS_LOG_ERROR("Cannot delete inexistent path: " + name);
       ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentItem);
     }
     else
@@ -215,7 +215,7 @@
   {
     if (path.empty())
     {
-      OrthancPlugins::LogError("Empty path");
+      ORTHANC_PLUGINS_LOG_ERROR("Empty path");
       ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
     else