diff Core/Logging.cpp @ 2243:2dbfdafc2512

Logger compatible with the Orthanc plugin SDK
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Dec 2016 16:02:00 +0100
parents fd5875662670
children a3a65de1840f
line wrap: on
line diff
--- a/Core/Logging.cpp	Mon Dec 19 15:31:01 2016 +0100
+++ b/Core/Logging.cpp	Fri Dec 23 16:02:00 2016 +0100
@@ -73,7 +73,74 @@
   }
 }
 
-#else
+
+#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+
+/*********************************************************
+ * Logger compatible with the Orthanc plugin SDK
+ *********************************************************/
+
+#include <boost/lexical_cast.hpp>
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    static OrthancPluginContext* context_ = NULL;
+
+    void Initialize(OrthancPluginContext* context)
+    {
+      context_ = context_;
+    }
+
+    InternalLogger::InternalLogger(const char* level,
+                                   const char* file  /* ignored */,
+                                   int line  /* ignored */) :
+      level_(level)
+    {
+    }
+
+    InternalLogger::~InternalLogger()
+    {
+      if (context_ != NULL)
+      {
+        if (level_ == "ERROR")
+        {
+          OrthancPluginLogError(context_, message_.c_str());
+        }
+        else if (level_ == "WARNING")
+        {
+          OrthancPluginLogWarning(context_, message_.c_str());
+        }
+        else if (level_ == "INFO")
+        {
+          OrthancPluginLogInfo(context_, message_.c_str());
+        }
+      }
+    }
+
+    InternalLogger& InternalLogger::operator<< (const std::string& message)
+    {
+      message_ += message;
+      return *this;
+    }
+
+    InternalLogger& InternalLogger::operator<< (const char* message)
+    {
+      message_ += std::string(message);
+      return *this;
+    }
+
+    InternalLogger& InternalLogger::operator<< (int message)
+    {
+      message_ += boost::lexical_cast<std::string>(message);
+      return *this;
+    }
+  }
+}
+
+
+#else  /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
 
 /*********************************************************
  * Internal logger of Orthanc, that mimics some