comparison Core/Logging.h @ 1495:fbe40117eb21

improve the performance of the internal logger
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Aug 2015 18:19:32 +0200
parents e460341872dc
children 46b2794042d6
comparison
equal deleted inserted replaced
1494:a13581480b1f 1495:fbe40117eb21
33 #pragma once 33 #pragma once
34 34
35 #if ORTHANC_ENABLE_LOGGING == 1 35 #if ORTHANC_ENABLE_LOGGING == 1
36 36
37 #if ORTHANC_ENABLE_GOOGLE_LOG == 1 37 #if ORTHANC_ENABLE_GOOGLE_LOG == 1
38 # include <stdlib.h> // This fixes a problem in glog for recent releases of MinGW 38 # include <stdlib.h> // Including this fixes a problem in glog for recent releases of MinGW
39 # include <glog/logging.h> 39 # include <glog/logging.h>
40 #else 40 #else
41 # include <iostream> 41 # include <iostream>
42 # include <boost/thread/mutex.hpp> 42 # include <boost/thread/mutex.hpp>
43 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) 43 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__)
44 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) 44 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
45 #endif 45 #endif
46 46
47 47
48 namespace Orthanc 48 namespace Orthanc
57 57
58 void EnableTraceLevel(bool enabled); 58 void EnableTraceLevel(bool enabled);
59 59
60 void SetTargetFolder(const std::string& path); 60 void SetTargetFolder(const std::string& path);
61 61
62 #if ORTHANC_ENABLE_GOOGLE_LOG != 1
63 struct NullStream : public std::ostream
64 {
65 NullStream() :
66 std::ios(0),
67 std::ostream(0)
68 {
69 }
70 };
62 71
63 #if ORTHANC_ENABLE_GOOGLE_LOG != 1
64 class InternalLogger 72 class InternalLogger
65 { 73 {
66 private: 74 private:
67 boost::mutex::scoped_lock lock_; 75 boost::mutex::scoped_lock lock_;
68 std::ostream* stream_; 76 NullStream null_;
77 std::ostream* stream_;
69 78
70 public: 79 public:
71 InternalLogger(const char* level, 80 InternalLogger(const char* level,
72 const char* file, 81 const char* file,
73 int line); 82 int line);
78 *stream_ << "\r\n"; 87 *stream_ << "\r\n";
79 #else 88 #else
80 *stream_ << "\n"; 89 *stream_ << "\n";
81 #endif 90 #endif
82 } 91 }
83 92
84 std::ostream& operator<< (const std::string& message) 93 std::ostream& operator<< (const std::string& message)
85 { 94 {
86 return (*stream_) << message; 95 return (*stream_) << message;
87 } 96 }
88 }; 97 };