diff Orthanc/Core/Logging.h @ 159:5dc54316d68b

shared copyright with osimis
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Jan 2017 16:41:43 +0100
parents 8189115c0da5
children dd1ad819ca33
line wrap: on
line diff
--- a/Orthanc/Core/Logging.h	Wed Dec 14 16:49:00 2016 +0100
+++ b/Orthanc/Core/Logging.h	Wed Jan 04 16:41:43 2017 +0100
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -38,11 +39,27 @@
 #  error The macro ORTHANC_ENABLE_LOGGING must be defined
 #endif
 
+#if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN)
+#  if ORTHANC_ENABLE_LOGGING == 1
+#    error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined
+#  else
+#    define ORTHANC_ENABLE_LOGGING_PLUGIN 0
+#  endif
+#endif
+
+#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+#  include <orthanc/OrthancCPlugin.h>
+#endif
+
 namespace Orthanc
 {
   namespace Logging
   {
+#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+    void Initialize(OrthancPluginContext* context);
+#else
     void Initialize();
+#endif
 
     void Finalize();
 
@@ -86,7 +103,41 @@
 #  define LOG(level)   ::Orthanc::Logging::NullStream()
 #  define VLOG(level)  ::Orthanc::Logging::NullStream()
 
-#else  /* ORTHANC_ENABLE_LOGGING == 1 */
+
+#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+
+#  include <boost/noncopyable.hpp>
+#  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
+#  define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    class InternalLogger : public boost::noncopyable
+    {
+    private:
+      std::string level_;
+      std::string message_;
+
+    public:
+      InternalLogger(const char* level,
+                     const char* file,
+                     int line);
+
+      ~InternalLogger();
+      
+      InternalLogger& operator<< (const std::string& message);
+
+      InternalLogger& operator<< (const char* message);
+
+      InternalLogger& operator<< (int message);
+    };
+  }
+}
+
+
+#else  /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
 
 #  include <boost/thread/mutex.hpp>
 #  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)