Mercurial > hg > orthanc
comparison Core/Logging.cpp @ 3489:e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
use an std::stringstream so that manipulators like "std::hex" are supported
(when using ORTHANC_ENABLE_LOGGING_PLUGIN or ORTHANC_ENABLE_LOGGING_STDIO)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Sat, 10 Aug 2019 13:40:08 +0200 |
parents | a4f2354f04c3 |
children | b2d4dd16dae8 |
comparison
equal
deleted
inserted
replaced
3487:ce29644acd19 | 3489:e7723a39adf8 |
---|---|
90 /********************************************************* | 90 /********************************************************* |
91 * Logger compatible with the Orthanc plugin SDK | 91 * Logger compatible with the Orthanc plugin SDK |
92 *********************************************************/ | 92 *********************************************************/ |
93 | 93 |
94 #include <boost/lexical_cast.hpp> | 94 #include <boost/lexical_cast.hpp> |
95 #include <sstream> | |
95 | 96 |
96 namespace Orthanc | 97 namespace Orthanc |
97 { | 98 { |
98 namespace Logging | 99 namespace Logging |
99 { | 100 { |
111 { | 112 { |
112 } | 113 } |
113 | 114 |
114 InternalLogger::~InternalLogger() | 115 InternalLogger::~InternalLogger() |
115 { | 116 { |
117 std::string message = messageStream_.str(); | |
116 if (context_ != NULL) | 118 if (context_ != NULL) |
117 { | 119 { |
118 switch (level_) | 120 switch (level_) |
119 { | 121 { |
120 case InternalLevel_ERROR: | 122 case InternalLevel_ERROR: |
121 OrthancPluginLogError(context_, message_.c_str()); | 123 OrthancPluginLogError(context_, message.c_str()); |
122 break; | 124 break; |
123 | 125 |
124 case InternalLevel_WARNING: | 126 case InternalLevel_WARNING: |
125 OrthancPluginLogWarning(context_, message_.c_str()); | 127 OrthancPluginLogWarning(context_, message.c_str()); |
126 break; | 128 break; |
127 | 129 |
128 case InternalLevel_INFO: | 130 case InternalLevel_INFO: |
129 OrthancPluginLogInfo(context_, message_.c_str()); | 131 OrthancPluginLogInfo(context_, message.c_str()); |
130 break; | 132 break; |
131 | 133 |
132 case InternalLevel_TRACE: | 134 case InternalLevel_TRACE: |
133 // Not used by plugins | 135 // Not used by plugins |
134 break; | 136 break; |
135 | 137 |
136 default: | 138 default: |
137 { | 139 { |
138 std::string s = ("Unknown log level (" + boost::lexical_cast<std::string>(level_) + | 140 std::string s = ("Unknown log level (" + boost::lexical_cast<std::string>(level_) + |
139 ") for message: " + message_); | 141 ") for message: " + message); |
140 OrthancPluginLogError(context_, s.c_str()); | 142 OrthancPluginLogError(context_, s.c_str()); |
141 break; | 143 break; |
142 } | 144 } |
143 } | 145 } |
144 } | 146 } |
237 { | 239 { |
238 } | 240 } |
239 | 241 |
240 InternalLogger::~InternalLogger() | 242 InternalLogger::~InternalLogger() |
241 { | 243 { |
244 std::string message = messageStream_.str(); | |
245 | |
242 switch (level_) | 246 switch (level_) |
243 { | 247 { |
244 case InternalLevel_ERROR: | 248 case InternalLevel_ERROR: |
245 globalErrorLogFunc(message_.c_str()); | 249 globalErrorLogFunc(message.c_str()); |
246 break; | 250 break; |
247 | 251 |
248 case InternalLevel_WARNING: | 252 case InternalLevel_WARNING: |
249 globalWarningLogFunc(message_.c_str()); | 253 globalWarningLogFunc(message.c_str()); |
250 break; | 254 break; |
251 | 255 |
252 case InternalLevel_INFO: | 256 case InternalLevel_INFO: |
253 if (globalVerbose_) | 257 if (globalVerbose_) |
254 { | 258 { |
255 globalInfoLogFunc(message_.c_str()); | 259 globalInfoLogFunc(message.c_str()); |
256 // TODO: stone_console_info(message_.c_str()); | 260 // TODO: stone_console_info(message_.c_str()); |
257 } | 261 } |
258 break; | 262 break; |
259 | 263 |
260 case InternalLevel_TRACE: | 264 case InternalLevel_TRACE: |
261 if (globalTrace_) | 265 if (globalTrace_) |
262 { | 266 { |
263 globalTraceLogFunc(message_.c_str()); | 267 globalTraceLogFunc(message.c_str()); |
264 } | 268 } |
265 break; | 269 break; |
266 | 270 |
267 default: | 271 default: |
268 { | 272 { |
269 std::stringstream ss; | 273 std::stringstream ss; |
270 ss << "Unknown log level (" << level_ << ") for message: " << message_; | 274 ss << "Unknown log level (" << level_ << ") for message: " << message; |
271 auto s = ss.str(); | 275 auto s = ss.str(); |
272 globalErrorLogFunc(s.c_str()); | 276 globalErrorLogFunc(s.c_str()); |
273 } | 277 } |
274 } | 278 } |
275 } | 279 } |