Mercurial > hg > orthanc
comparison Core/Logging.h @ 3998:b3f09bc9734b
sharing more code between the loggers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Jun 2020 18:56:35 +0200 |
parents | c2b9a7a1c74a |
children | 5d5662ff4d5c |
comparison
equal
deleted
inserted
replaced
3997:febe25d03f08 | 3998:b3f09bc9734b |
---|---|
62 | 62 |
63 namespace Orthanc | 63 namespace Orthanc |
64 { | 64 { |
65 namespace Logging | 65 namespace Logging |
66 { | 66 { |
67 enum Level | 67 enum LogLevel |
68 { | 68 { |
69 Level_ERROR, | 69 LogLevel_ERROR, |
70 Level_WARNING, | 70 LogLevel_WARNING, |
71 Level_INFO, | 71 LogLevel_INFO, |
72 Level_TRACE | 72 LogLevel_TRACE |
73 }; | 73 }; |
74 | 74 |
75 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level); | |
76 | |
77 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level); | |
78 | |
75 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 | 79 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
76 // "pluginContext" must be of type "OrthancPluginContext" | 80 // "pluginContext" must be of type "OrthancPluginContext" |
77 ORTHANC_PUBLIC void Initialize(void* pluginContext); | 81 ORTHANC_PUBLIC void Initialize(void* pluginContext); |
78 #else | 82 #else |
79 ORTHANC_PUBLIC void Initialize(); | 83 ORTHANC_PUBLIC void Initialize(); |
120 } | 124 } |
121 }; | 125 }; |
122 } | 126 } |
123 } | 127 } |
124 | 128 |
129 | |
125 #if ORTHANC_ENABLE_LOGGING != 1 | 130 #if ORTHANC_ENABLE_LOGGING != 1 |
126 | |
127 # define LOG(level) ::Orthanc::Logging::NullStream() | 131 # define LOG(level) ::Orthanc::Logging::NullStream() |
128 # define VLOG(level) ::Orthanc::Logging::NullStream() | 132 # define VLOG(level) ::Orthanc::Logging::NullStream() |
129 | 133 #else |
130 #elif (ORTHANC_ENABLE_LOGGING_PLUGIN == 1 || \ | 134 # define LOG(level) ::Orthanc::Logging::InternalLogger \ |
131 ORTHANC_ENABLE_LOGGING_STDIO == 1) | 135 (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__) |
132 | |
133 # include <boost/noncopyable.hpp> | |
134 # define LOG(level) ::Orthanc::Logging::InternalLogger \ | |
135 (::Orthanc::Logging::Level_ ## level, __FILE__, __LINE__) | |
136 # define VLOG(level) ::Orthanc::Logging::InternalLogger \ | 136 # define VLOG(level) ::Orthanc::Logging::InternalLogger \ |
137 (::Orthanc::Logging::Level_TRACE, __FILE__, __LINE__) | 137 (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__) |
138 #endif | |
139 | |
140 | |
141 #if (ORTHANC_ENABLE_LOGGING == 1 && \ | |
142 (ORTHANC_ENABLE_LOGGING_PLUGIN == 1 || \ | |
143 ORTHANC_ENABLE_LOGGING_STDIO == 1)) | |
144 | |
145 #include <boost/noncopyable.hpp> | |
138 | 146 |
139 namespace Orthanc | 147 namespace Orthanc |
140 { | 148 { |
141 namespace Logging | 149 namespace Logging |
142 { | 150 { |
143 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable | 151 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable |
144 { | 152 { |
145 private: | 153 private: |
146 Level level_; | 154 LogLevel level_; |
147 std::stringstream messageStream_; | 155 std::stringstream messageStream_; |
148 | 156 |
149 public: | 157 public: |
150 InternalLogger(Level level, | 158 InternalLogger(LogLevel level, |
151 const char* file, | 159 const char* file, |
152 int line); | 160 int line); |
153 | 161 |
154 ~InternalLogger(); | 162 ~InternalLogger(); |
155 | 163 |
161 } | 169 } |
162 }; | 170 }; |
163 } | 171 } |
164 } | 172 } |
165 | 173 |
166 | 174 #endif |
167 | 175 |
168 | 176 |
169 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && | 177 |
170 ORTHANC_ENABLE_LOGGING_STDIO == 0 && | 178 |
171 ORTHANC_ENABLE_LOGGING == 1 */ | 179 #if (ORTHANC_ENABLE_LOGGING == 1 && \ |
172 | 180 ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && \ |
173 # include <boost/thread/mutex.hpp> | 181 ORTHANC_ENABLE_LOGGING_STDIO == 0) |
174 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) | 182 |
175 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) | 183 #include <boost/thread/mutex.hpp> |
176 | |
177 | 184 |
178 namespace Orthanc | 185 namespace Orthanc |
179 { | 186 { |
180 namespace Logging | 187 namespace Logging |
181 { | 188 { |
185 boost::mutex::scoped_lock lock_; | 192 boost::mutex::scoped_lock lock_; |
186 NullStream null_; | 193 NullStream null_; |
187 std::ostream* stream_; | 194 std::ostream* stream_; |
188 | 195 |
189 public: | 196 public: |
190 InternalLogger(const char* level, | 197 InternalLogger(LogLevel level, |
191 const char* file, | 198 const char* file, |
192 int line); | 199 int line); |
193 | 200 |
194 ~InternalLogger(); | 201 ~InternalLogger(); |
195 | 202 |
264 ORTHANC_PUBLIC void EnableEmscriptenLogging(); | 271 ORTHANC_PUBLIC void EnableEmscriptenLogging(); |
265 #endif | 272 #endif |
266 } | 273 } |
267 } | 274 } |
268 | 275 |
269 #endif // ORTHANC_ENABLE_LOGGING | 276 #endif |