Mercurial > hg > orthanc
comparison Core/Logging.cpp @ 4017:c783f4f29390
log using emscripten
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 18:15:31 +0200 |
parents | 27628b0f6ada |
children | 05a363186da6 |
comparison
equal
deleted
inserted
replaced
4016:c675d77b82ab | 4017:c783f4f29390 |
---|---|
161 | 161 |
162 namespace Orthanc | 162 namespace Orthanc |
163 { | 163 { |
164 namespace Logging | 164 namespace Logging |
165 { | 165 { |
166 static bool globalVerbose_ = false; | 166 static bool infoEnabled_ = false; |
167 static bool globalTrace_ = false; | 167 static bool traceEnabled_ = false; |
168 | 168 |
169 #ifdef __EMSCRIPTEN__ | 169 #ifdef __EMSCRIPTEN__ |
170 static void ErrorLogFunc(const char* msg) | 170 static void ErrorLogFunc(const char* msg) |
171 { | 171 { |
172 emscripten_console_error(msg); | 172 emscripten_console_error(msg); |
206 { | 206 { |
207 fprintf(stdout, "T: %s\n", msg); | 207 fprintf(stdout, "T: %s\n", msg); |
208 } | 208 } |
209 #endif /* __EMSCRIPTEN__ */ | 209 #endif /* __EMSCRIPTEN__ */ |
210 | 210 |
211 InternalLogger::InternalLogger(LogLevel level, | |
212 const char* file /* ignored */, | |
213 int line /* ignored */) : | |
214 level_(level) | |
215 { | |
216 } | |
217 | 211 |
218 InternalLogger::~InternalLogger() | 212 InternalLogger::~InternalLogger() |
219 { | 213 { |
220 std::string message = messageStream_.str(); | 214 std::string message = messageStream_.str(); |
221 | 215 |
222 switch (level_) | 216 switch (level_) |
223 { | 217 { |
224 case LogLevel_ERROR: | 218 case LogLevel_ERROR: |
225 globalErrorLogFunc(message.c_str()); | 219 ErrorLogFunc(message.c_str()); |
226 break; | 220 break; |
227 | 221 |
228 case LogLevel_WARNING: | 222 case LogLevel_WARNING: |
229 globalWarningLogFunc(message.c_str()); | 223 WarningLogFunc(message.c_str()); |
230 break; | 224 break; |
231 | 225 |
232 case LogLevel_INFO: | 226 case LogLevel_INFO: |
233 if (globalVerbose_) | 227 if (infoEnabled_) |
234 { | 228 { |
235 globalInfoLogFunc(message.c_str()); | 229 InfoLogFunc(message.c_str()); |
236 // TODO: stone_console_info(message_.c_str()); | 230 // TODO: stone_console_info(message_.c_str()); |
237 } | 231 } |
238 break; | 232 break; |
239 | 233 |
240 case LogLevel_TRACE: | 234 case LogLevel_TRACE: |
241 if (globalTrace_) | 235 if (traceEnabled_) |
242 { | 236 { |
243 globalTraceLogFunc(message.c_str()); | 237 TraceLogFunc(message.c_str()); |
244 } | 238 } |
245 break; | 239 break; |
246 | 240 |
247 default: | 241 default: |
248 { | 242 { |
249 std::stringstream ss; | 243 std::stringstream ss; |
250 ss << "Unknown log level (" << level_ << ") for message: " << message; | 244 ss << "Unknown log level (" << level_ << ") for message: " << message; |
251 std::string s = ss.str(); | 245 std::string s = ss.str(); |
252 globalErrorLogFunc(s.c_str()); | 246 ErrorLogFunc(s.c_str()); |
253 } | 247 } |
254 } | 248 } |
255 } | 249 } |
256 | 250 |
257 void InitializePluginContext(void* pluginContext) | 251 void InitializePluginContext(void* pluginContext) |
274 { | 268 { |
275 } | 269 } |
276 | 270 |
277 void EnableInfoLevel(bool enabled) | 271 void EnableInfoLevel(bool enabled) |
278 { | 272 { |
279 globalVerbose_ = enabled; | 273 infoEnabled_ = enabled; |
274 | |
275 if (!enabled) | |
276 { | |
277 // Also disable the "TRACE" level when info-level debugging is disabled | |
278 traceEnabled_ = false; | |
279 } | |
280 } | 280 } |
281 | 281 |
282 bool IsInfoLevelEnabled() | 282 bool IsInfoLevelEnabled() |
283 { | 283 { |
284 return globalVerbose_; | 284 return infoEnabled_; |
285 } | 285 } |
286 | 286 |
287 void EnableTraceLevel(bool enabled) | 287 void EnableTraceLevel(bool enabled) |
288 { | 288 { |
289 globalTrace_ = enabled; | 289 traceEnabled_ = enabled; |
290 } | 290 } |
291 | 291 |
292 bool IsTraceLevelEnabled() | 292 bool IsTraceLevelEnabled() |
293 { | 293 { |
294 return globalTrace_; | 294 return traceEnabled_; |
295 } | 295 } |
296 | 296 |
297 void SetTargetFile(const std::string& path) | 297 void SetTargetFile(const std::string& path) |
298 { | 298 { |
299 } | 299 } |
758 case LogLevel_ERROR: | 758 case LogLevel_ERROR: |
759 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogError, message.c_str()); | 759 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogError, message.c_str()); |
760 break; | 760 break; |
761 | 761 |
762 case LogLevel_WARNING: | 762 case LogLevel_WARNING: |
763 printf("[%s]\n", message.c_str()); | |
764 | |
765 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogWarning, message.c_str()); | 763 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogWarning, message.c_str()); |
766 break; | 764 break; |
767 | 765 |
768 case LogLevel_INFO: | 766 case LogLevel_INFO: |
769 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogInfo, message.c_str()); | 767 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogInfo, message.c_str()); |