diff OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp @ 5561:0b18690c1935

SDK: added OrthancPluginLogMessage to display plugin name + file and line from plugin
author Alain Mazy <am@orthanc.team>
date Tue, 23 Apr 2024 09:34:02 +0200
parents c1ed59a5bdc2
children e02cdf358905
line wrap: on
line diff
--- a/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Mon Apr 22 10:50:33 2024 +0200
+++ b/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Tue Apr 23 09:34:02 2024 +0200
@@ -23,6 +23,7 @@
 #define HOUSEKEEPER_NAME "housekeeper"
 
 #include "../../../../OrthancFramework/Sources/Compatibility.h"
+#include "../../../../OrthancFramework/Sources/Logging.h"
 #include "../Common/OrthancPluginCppWrapper.h"
 
 #include <boost/thread.hpp>
@@ -91,7 +92,7 @@
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: invalid schedule: unknown 'day': " + weekday);      
+      LOG(WARNING) << "Housekeeper: invalid schedule: unknown 'day': " << weekday;
       ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
@@ -403,12 +404,12 @@
   {
     if (triggerOnUnnecessaryDicomAsJsonFiles_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: your storage might still contain some dicom-as-json files -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: your storage might still contain some dicom-as-json files -> will perform housekeeping";
       needsReconstruct = true;  // the default reconstruct removes the dicom-as-json
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: your storage might still contain some dicom-as-json files but the trigger has been disabled");
+      LOG(WARNING) << "Housekeeper: your storage might still contain some dicom-as-json files but the trigger has been disabled";
     }
   }
 
@@ -416,12 +417,12 @@
   {
     if (triggerOnMainDicomTagsChange_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: Patient main dicom tags have changed, -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: Patient main dicom tags have changed, -> will perform housekeeping";
       needsReconstruct = true;
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: Patient main dicom tags have changed but the trigger is disabled");
+      LOG(WARNING) << "Housekeeper: Patient main dicom tags have changed but the trigger is disabled";
     }
   }
 
@@ -429,12 +430,12 @@
   {
     if (triggerOnMainDicomTagsChange_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: Study main dicom tags have changed, -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: Study main dicom tags have changed, -> will perform housekeeping";
       needsReconstruct = true;
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: Study main dicom tags have changed but the trigger is disabled");
+      LOG(WARNING) << "Housekeeper: Study main dicom tags have changed but the trigger is disabled";
     }
   }
 
@@ -442,12 +443,12 @@
   {
     if (triggerOnMainDicomTagsChange_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: Series main dicom tags have changed, -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: Series main dicom tags have changed, -> will perform housekeeping";
       needsReconstruct = true;
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: Series main dicom tags have changed but the trigger is disabled");
+      LOG(WARNING) << "Housekeeper: Series main dicom tags have changed but the trigger is disabled";
     }
   }
 
@@ -455,12 +456,12 @@
   {
     if (triggerOnMainDicomTagsChange_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: Instance main dicom tags have changed, -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: Instance main dicom tags have changed, -> will perform housekeeping";
       needsReconstruct = true;
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: Instance main dicom tags have changed but the trigger is disabled");
+      LOG(WARNING) << "Housekeeper: Instance main dicom tags have changed but the trigger is disabled";
     }
   }
 
@@ -470,18 +471,18 @@
     {
       if (current.storageCompressionEnabled)
       {
-        OrthancPlugins::LogWarning("Housekeeper: storage compression is now enabled -> will perform housekeeping");
+        LOG(WARNING) << "Housekeeper: storage compression is now enabled -> will perform housekeeping";
       }
       else
       {
-        OrthancPlugins::LogWarning("Housekeeper: storage compression is now disabled -> will perform housekeeping");
+        LOG(WARNING) << "Housekeeper: storage compression is now disabled -> will perform housekeeping";
       }
       
       needsReingest = true;
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: storage compression has changed but the trigger is disabled");
+      LOG(WARNING) << "Housekeeper: storage compression has changed but the trigger is disabled";
     }
   }
 
@@ -489,13 +490,13 @@
   {
     if (triggerOnIngestTranscodingChange_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: ingest transcoding has changed -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: ingest transcoding has changed -> will perform housekeeping";
       
       needsReingest = true;
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: ingest transcoding has changed but the trigger is disabled");
+      LOG(WARNING) << "Housekeeper: ingest transcoding has changed but the trigger is disabled";
     }
   }
 
@@ -505,7 +506,7 @@
     {
       if (triggerOnDicomWebCacheChange_)
       {
-        OrthancPlugins::LogWarning("Housekeeper: DicomWEB plugin is enabled and the housekeeper has never run, you might miss series metadata cache -> will perform housekeeping");
+        LOG(WARNING) << "Housekeeper: DicomWEB plugin is enabled and the housekeeper has never run, you might miss series metadata cache -> will perform housekeeping";
       }
       needsDicomWebCaching = triggerOnDicomWebCacheChange_;
     }
@@ -517,12 +518,12 @@
       {
         if (triggerOnDicomWebCacheChange_)
         {
-          OrthancPlugins::LogWarning("Housekeeper: DicomWEB plugin might miss series metadata cache -> will perform housekeeping");
+          LOG(WARNING) << "Housekeeper: DicomWEB plugin might miss series metadata cache -> will perform housekeeping";
           needsDicomWebCaching = true;
         }
         else
         {
-          OrthancPlugins::LogWarning("Housekeeper: DicomWEB plugin might miss series metadata cache but the trigger has been disabled");
+          LOG(WARNING) << "Housekeeper: DicomWEB plugin might miss series metadata cache but the trigger has been disabled";
         }
       }
     }
@@ -659,7 +660,7 @@
 
   if (!needsProcessing)
   {
-    OrthancPlugins::LogWarning("Housekeeper: everything has been processed already !");
+    LOG(WARNING) << "Housekeeper: everything has been processed already !";
     return;
   }
 
@@ -667,11 +668,11 @@
   {
     if (force_)
     {
-      OrthancPlugins::LogWarning("Housekeeper: forcing execution -> will perform housekeeping");
+      LOG(WARNING) << "Housekeeper: forcing execution -> will perform housekeeping";
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper: the DB configuration has changed since last run, will reprocess the whole DB !");
+      LOG(WARNING) << "Housekeeper: the DB configuration has changed since last run, will reprocess the whole DB !";
     }
     
     Json::Value changes;
@@ -687,7 +688,7 @@
   }
   else
   {
-    OrthancPlugins::LogWarning("Housekeeper: the DB configuration has not changed since last run, will continue processing changes");
+    LOG(WARNING) << "Housekeeper: the DB configuration has not changed since last run, will continue processing changes";
   }
 
   bool completed = false;
@@ -709,9 +710,7 @@
       {
         boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_);
     
-        OrthancPlugins::LogInfo("Housekeeper: processed changes " + 
-                                boost::lexical_cast<std::string>(pluginStatus_.lastProcessedChange) + 
-                                " / " + boost::lexical_cast<std::string>(pluginStatus_.lastChangeToProcess));
+        LOG(INFO) << "Housekeeper: processed changes " << pluginStatus_.lastProcessedChange << " / " << pluginStatus_.lastChangeToProcess;
         
         boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 100));  // wait 1/10 of the delay between changes
       }
@@ -722,7 +721,7 @@
     {
       if (!loggedNotRightPeriodChangeMessage)
       {
-        OrthancPlugins::LogInfo("Housekeeper: entering quiet period");
+        LOG(INFO) << "Housekeeper: entering quiet period";
         loggedNotRightPeriodChangeMessage = true;
       }
 
@@ -807,7 +806,7 @@
       return -1;
     }
 
-    OrthancPlugins::LogWarning("Housekeeper plugin is initializing");
+    LOG(WARNING) << "Housekeeper plugin is initializing";
     OrthancPluginSetDescription2(c, HOUSEKEEPER_NAME, "Optimizes your DB and storage.");
 
     OrthancPlugins::OrthancConfiguration orthancConfiguration;
@@ -891,7 +890,7 @@
       if (limitMainDicomTagsReconstructLevel_ != "Patient" && limitMainDicomTagsReconstructLevel_ != "Study"
         && limitMainDicomTagsReconstructLevel_ != "Series" && limitMainDicomTagsReconstructLevel_ != "Instance")
       {
-        OrthancPlugins::LogError("Housekeeper invalid value for 'LimitMainDicomTagsReconstructLevel': '" + limitMainDicomTagsReconstructLevel_ + "'");
+        LOG(ERROR) << "Housekeeper invalid value for 'LimitMainDicomTagsReconstructLevel': '" << limitMainDicomTagsReconstructLevel_ << "'";
       }
       else if (limitMainDicomTagsReconstructLevel_ == "Patient")
       {
@@ -925,7 +924,7 @@
     }
     else
     {
-      OrthancPlugins::LogWarning("Housekeeper plugin is disabled by the configuration file");
+      LOG(WARNING) << "Housekeeper plugin is disabled by the configuration file";
     }
 
     return 0;
@@ -934,7 +933,7 @@
 
   ORTHANC_PLUGINS_API void OrthancPluginFinalize()
   {
-    OrthancPlugins::LogWarning("Housekeeper plugin is finalizing");
+    LOG(WARNING) << "Housekeeper plugin is finalizing";
   }