diff Core/Logging.h @ 1489:1389834e130f

basic logger
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Aug 2015 12:22:08 +0200
parents c8763b603b0e
children e460341872dc
line wrap: on
line diff
--- a/Core/Logging.h	Tue Aug 04 10:54:13 2015 +0200
+++ b/Core/Logging.h	Tue Aug 04 12:22:08 2015 +0200
@@ -35,10 +35,16 @@
 #if ORTHANC_ENABLE_LOGGING == 1
 
 #if ORTHANC_ENABLE_GOOGLE_LOG == 1
-#include <stdlib.h>  // This fixes a problem in glog for recent releases of MinGW
-#include <glog/logging.h>
+#  include <stdlib.h>  // 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
 
+
 namespace Orthanc
 {
   namespace Logging
@@ -50,6 +56,37 @@
     void EnableInfoLevel(bool enabled);
 
     void EnableTraceLevel(bool enabled);
+
+    void SetTargetFolder(const std::string& path);
+
+
+#if ORTHANC_ENABLE_GOOGLE_LOG != 1
+    class InternalLogger
+    {
+    private:
+      boost::mutex::scoped_lock  lock_;
+      std::ostream*              stream_;
+
+    public:
+      InternalLogger(const char* level,
+                     const char* file,
+                     int line);
+
+      ~InternalLogger()
+      {
+#if defined(_WIN32)
+        *stream_ << "\r\n";
+#else
+        *stream_ << "\n";
+#endif
+      }
+
+      std::ostream& operator<< (const std::string& message)
+      {
+        return (*stream_) << message;
+      }
+    };
+#endif
   }
 }