Mercurial > hg > orthanc
comparison Core/Logging.h @ 1551:0dba274074eb
standalone logging
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Aug 2015 14:57:41 +0200 |
parents | 46b2794042d6 |
children | b1291df2f780 |
comparison
equal
deleted
inserted
replaced
1550:2c7d5eb588e6 | 1551:0dba274074eb |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #pragma once | 33 #pragma once |
34 | 34 |
35 #if ORTHANC_ENABLE_LOGGING == 1 | 35 #include <iostream> |
36 | |
37 #if ORTHANC_ENABLE_GOOGLE_LOG == 1 | |
38 # include <stdlib.h> // Including this fixes a problem in glog for recent releases of MinGW | |
39 # include <glog/logging.h> | |
40 #else | |
41 # include <iostream> | |
42 # include <boost/thread/mutex.hpp> | |
43 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) | |
44 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) | |
45 #endif | |
46 | |
47 | 36 |
48 namespace Orthanc | 37 namespace Orthanc |
49 { | 38 { |
50 namespace Logging | 39 namespace Logging |
51 { | 40 { |
57 | 46 |
58 void EnableTraceLevel(bool enabled); | 47 void EnableTraceLevel(bool enabled); |
59 | 48 |
60 void SetTargetFolder(const std::string& path); | 49 void SetTargetFolder(const std::string& path); |
61 | 50 |
62 #if ORTHANC_ENABLE_GOOGLE_LOG != 1 | |
63 struct NullStream : public std::ostream | 51 struct NullStream : public std::ostream |
64 { | 52 { |
65 NullStream() : | 53 NullStream() : |
66 std::ios(0), | 54 std::ios(0), |
67 std::ostream(0) | 55 std::ostream(0) |
68 { | 56 { |
69 } | 57 } |
58 | |
59 std::ostream& operator<< (const std::string& message) | |
60 { | |
61 return *this; | |
62 } | |
70 }; | 63 }; |
64 } | |
65 } | |
71 | 66 |
67 | |
68 #if ORTHANC_ENABLE_LOGGING != 1 | |
69 | |
70 # define LOG(level) ::Orthanc::Logging::NullStream() | |
71 # define VLOG(level) ::Orthanc::Logging::NullStream() | |
72 | |
73 #else /* ORTHANC_ENABLE_LOGGING == 1 */ | |
74 | |
75 #if ORTHANC_ENABLE_GOOGLE_LOG == 1 | |
76 # include <stdlib.h> // Including this fixes a problem in glog for recent releases of MinGW | |
77 # include <glog/logging.h> | |
78 #else | |
79 # include <boost/thread/mutex.hpp> | |
80 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) | |
81 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) | |
82 #endif | |
83 | |
84 #if ORTHANC_ENABLE_GOOGLE_LOG != 1 | |
85 namespace Orthanc | |
86 { | |
87 namespace Logging | |
88 { | |
72 class InternalLogger | 89 class InternalLogger |
73 { | 90 { |
74 private: | 91 private: |
75 boost::mutex::scoped_lock lock_; | 92 boost::mutex::scoped_lock lock_; |
76 NullStream null_; | 93 NullStream null_; |
86 std::ostream& operator<< (const std::string& message) | 103 std::ostream& operator<< (const std::string& message) |
87 { | 104 { |
88 return (*stream_) << message; | 105 return (*stream_) << message; |
89 } | 106 } |
90 }; | 107 }; |
91 #endif | |
92 } | 108 } |
93 } | 109 } |
110 #endif | |
94 | 111 |
95 #endif // ORTHANC_ENABLE_LOGGING | 112 #endif // ORTHANC_ENABLE_LOGGING |