Mercurial > hg > orthanc-stone
comparison Resources/Orthanc/Core/Logging.h @ 202:e7f90aba3c97
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 26 Mar 2018 18:10:34 +0200 |
parents | 03afbee0cc7b |
children |
comparison
equal
deleted
inserted
replaced
201:e9c7a78a3e77 | 202:e7f90aba3c97 |
---|---|
57 | 57 |
58 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 | 58 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
59 # include <orthanc/OrthancCPlugin.h> | 59 # include <orthanc/OrthancCPlugin.h> |
60 #endif | 60 #endif |
61 | 61 |
62 #include <boost/lexical_cast.hpp> | |
63 | |
62 namespace Orthanc | 64 namespace Orthanc |
63 { | 65 { |
64 namespace Logging | 66 namespace Logging |
65 { | 67 { |
66 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 | 68 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
89 std::ios(0), | 91 std::ios(0), |
90 std::ostream(0) | 92 std::ostream(0) |
91 { | 93 { |
92 } | 94 } |
93 | 95 |
94 std::ostream& operator<< (const std::string& message) | 96 template <typename T> |
95 { | 97 std::ostream& operator<< (const T& message) |
96 return *this; | |
97 } | |
98 | |
99 // This overload fixes build problems with Visual Studio 2015 | |
100 std::ostream& operator<< (const char* message) | |
101 { | 98 { |
102 return *this; | 99 return *this; |
103 } | 100 } |
104 }; | 101 }; |
105 } | 102 } |
114 | 111 |
115 #elif (ORTHANC_ENABLE_LOGGING_PLUGIN == 1 || \ | 112 #elif (ORTHANC_ENABLE_LOGGING_PLUGIN == 1 || \ |
116 ORTHANC_ENABLE_LOGGING_STDIO == 1) | 113 ORTHANC_ENABLE_LOGGING_STDIO == 1) |
117 | 114 |
118 # include <boost/noncopyable.hpp> | 115 # include <boost/noncopyable.hpp> |
119 # include <boost/lexical_cast.hpp> | |
120 # define LOG(level) ::Orthanc::Logging::InternalLogger \ | 116 # define LOG(level) ::Orthanc::Logging::InternalLogger \ |
121 (::Orthanc::Logging::level, __FILE__, __LINE__) | 117 (::Orthanc::Logging::InternalLevel_ ## level, __FILE__, __LINE__) |
122 # define VLOG(level) ::Orthanc::Logging::InternalLogger \ | 118 # define VLOG(level) ::Orthanc::Logging::InternalLogger \ |
123 (::Orthanc::Logging::TRACE, __FILE__, __LINE__) | 119 (::Orthanc::Logging::InternalLevel_TRACE, __FILE__, __LINE__) |
124 | 120 |
125 namespace Orthanc | 121 namespace Orthanc |
126 { | 122 { |
127 namespace Logging | 123 namespace Logging |
128 { | 124 { |
129 enum Level | 125 enum InternalLevel |
130 { | 126 { |
131 ERROR, | 127 InternalLevel_ERROR, |
132 WARNING, | 128 InternalLevel_WARNING, |
133 INFO, | 129 InternalLevel_INFO, |
134 TRACE | 130 InternalLevel_TRACE |
135 }; | 131 }; |
136 | 132 |
137 class InternalLogger : public boost::noncopyable | 133 class InternalLogger : public boost::noncopyable |
138 { | 134 { |
139 private: | 135 private: |
140 Level level_; | 136 InternalLevel level_; |
141 std::string message_; | 137 std::string message_; |
142 | 138 |
143 public: | 139 public: |
144 InternalLogger(Level level, | 140 InternalLogger(InternalLevel level, |
145 const char* file, | 141 const char* file, |
146 int line); | 142 int line); |
147 | 143 |
148 ~InternalLogger(); | 144 ~InternalLogger(); |
149 | 145 |
150 template <typename T> | 146 template <typename T> |
151 InternalLogger& operator<< (T message) | 147 InternalLogger& operator<< (const T& message) |
152 { | 148 { |
153 message_ += boost::lexical_cast<std::string>(message); | 149 message_ += boost::lexical_cast<std::string>(message); |
154 return *this; | 150 return *this; |
155 } | 151 } |
156 }; | 152 }; |
184 const char* file, | 180 const char* file, |
185 int line); | 181 int line); |
186 | 182 |
187 ~InternalLogger(); | 183 ~InternalLogger(); |
188 | 184 |
189 std::ostream& operator<< (const std::string& message) | 185 template <typename T> |
186 std::ostream& operator<< (const T& message) | |
190 { | 187 { |
191 return (*stream_) << message; | 188 return (*stream_) << boost::lexical_cast<std::string>(message); |
192 } | |
193 | |
194 // This overload fixes build problems with Visual Studio 2015 | |
195 std::ostream& operator<< (const char* message) | |
196 { | |
197 return (*stream_) << message; | |
198 } | 189 } |
199 }; | 190 }; |
200 } | 191 } |
201 } | 192 } |
202 | 193 |