changeset 1551:0dba274074eb

standalone logging
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Aug 2015 14:57:41 +0200
parents 2c7d5eb588e6
children 729d69336919
files Core/Logging.cpp Core/Logging.h
diffstat 2 files changed, 58 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Logging.cpp	Mon Aug 17 15:57:44 2015 +0200
+++ b/Core/Logging.cpp	Tue Aug 18 14:57:41 2015 +0200
@@ -33,10 +33,35 @@
 #include "PrecompiledHeaders.h"
 #include "Logging.h"
 
-#if ORTHANC_ENABLE_LOGGING == 1
+#if ORTHANC_ENABLE_LOGGING != 1
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    void Initialize()
+    {
+    }
+
+    void Finalize()
+    {
+    }
 
+    void EnableInfoLevel(bool enabled)
+    {
+    }
 
-#if ORTHANC_ENABLE_GOOGLE_LOG == 1
+    void EnableTraceLevel(bool enabled)
+    {
+    }
+
+    void SetTargetFolder(const std::string& path)
+    {
+    }
+  }
+}
+
+#elif ORTHANC_ENABLE_GOOGLE_LOG == 1
 
 /*********************************************************
  * Wrapper around Google Log
@@ -393,7 +418,4 @@
   }
 }
 
-#endif
-
-
 #endif   // ORTHANC_ENABLE_LOGGING
--- a/Core/Logging.h	Mon Aug 17 15:57:44 2015 +0200
+++ b/Core/Logging.h	Tue Aug 18 14:57:41 2015 +0200
@@ -32,18 +32,7 @@
 
 #pragma once
 
-#if ORTHANC_ENABLE_LOGGING == 1
-
-#if ORTHANC_ENABLE_GOOGLE_LOG == 1
-#  include <stdlib.h>  // Including this fixes a problem in glog for recent releases of MinGW
-#  include <glog/logging.h>
-#else
-#  include <iostream>
-#  include <boost/thread/mutex.hpp>
-#  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
-#  define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
-#endif
-
+#include <iostream>
 
 namespace Orthanc
 {
@@ -59,7 +48,6 @@
 
     void SetTargetFolder(const std::string& path);
 
-#if ORTHANC_ENABLE_GOOGLE_LOG != 1
     struct NullStream : public std::ostream 
     {
       NullStream() : 
@@ -67,8 +55,37 @@
         std::ostream(0)
       {
       }
+      
+      std::ostream& operator<< (const std::string& message)
+      {
+        return *this;
+      }
     };
+  }
+}
 
+
+#if ORTHANC_ENABLE_LOGGING != 1
+
+#  define LOG(level)   ::Orthanc::Logging::NullStream()
+#  define VLOG(level)  ::Orthanc::Logging::NullStream()
+
+#else  /* ORTHANC_ENABLE_LOGGING == 1 */
+
+#if ORTHANC_ENABLE_GOOGLE_LOG == 1
+#  include <stdlib.h>  // Including this fixes a problem in glog for recent releases of MinGW
+#  include <glog/logging.h>
+#else
+#  include <boost/thread/mutex.hpp>
+#  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
+#  define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
+#endif
+
+#if ORTHANC_ENABLE_GOOGLE_LOG != 1
+namespace Orthanc
+{
+  namespace Logging
+  {
     class InternalLogger
     {
     private:
@@ -88,8 +105,8 @@
         return (*stream_) << message;
       }
     };
-#endif
   }
 }
+#endif
 
 #endif  // ORTHANC_ENABLE_LOGGING