Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp @ 4273:0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 03 Nov 2020 12:24:50 +0100 |
parents | 1ec3e1e18f50 |
children | d7a50b7b8466 |
comparison
equal
deleted
inserted
replaced
4272:1661544ea94d | 4273:0034f855c023 |
---|---|
37 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | 37 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" |
38 #include "../../../OrthancFramework/Sources/MetricsRegistry.h" | 38 #include "../../../OrthancFramework/Sources/MetricsRegistry.h" |
39 #include "../../Plugins/Engine/OrthancPlugins.h" | 39 #include "../../Plugins/Engine/OrthancPlugins.h" |
40 #include "../../Plugins/Engine/PluginsManager.h" | 40 #include "../../Plugins/Engine/PluginsManager.h" |
41 #include "../OrthancConfiguration.h" | 41 #include "../OrthancConfiguration.h" |
42 #include "../OrthancInitialization.h" | |
42 #include "../ServerContext.h" | 43 #include "../ServerContext.h" |
43 | |
44 | |
45 static const char* LOG_LEVEL_DEFAULT = "default"; | |
46 static const char* LOG_LEVEL_VERBOSE = "verbose"; | |
47 static const char* LOG_LEVEL_TRACE = "trace"; | |
48 | 44 |
49 | 45 |
50 namespace Orthanc | 46 namespace Orthanc |
51 { | 47 { |
52 // System information ------------------------------------------------------- | 48 // System information ------------------------------------------------------- |
495 } | 491 } |
496 | 492 |
497 | 493 |
498 static void GetLogLevel(RestApiGetCall& call) | 494 static void GetLogLevel(RestApiGetCall& call) |
499 { | 495 { |
500 std::string s; | 496 const std::string s = EnumerationToString(GetGlobalVerbosity()); |
501 | |
502 if (Logging::IsTraceLevelEnabled()) | |
503 { | |
504 s = LOG_LEVEL_TRACE; | |
505 } | |
506 else if (Logging::IsInfoLevelEnabled()) | |
507 { | |
508 s = LOG_LEVEL_VERBOSE; | |
509 } | |
510 else | |
511 { | |
512 s = LOG_LEVEL_DEFAULT; | |
513 } | |
514 | |
515 call.GetOutput().AnswerBuffer(s, MimeType_PlainText); | 497 call.GetOutput().AnswerBuffer(s, MimeType_PlainText); |
516 } | 498 } |
517 | 499 |
518 | 500 |
519 static void PutLogLevel(RestApiPutCall& call) | 501 static void PutLogLevel(RestApiPutCall& call) |
520 { | 502 { |
521 std::string body; | 503 std::string body; |
522 call.BodyToString(body); | 504 call.BodyToString(body); |
523 | 505 |
524 if (body == LOG_LEVEL_DEFAULT) | 506 SetGlobalVerbosity(StringToVerbosity(body)); |
525 { | 507 |
526 Logging::EnableInfoLevel(false); | |
527 Logging::EnableTraceLevel(false); | |
528 } | |
529 else if (body == LOG_LEVEL_VERBOSE) | |
530 { | |
531 Logging::EnableInfoLevel(true); | |
532 Logging::EnableTraceLevel(false); | |
533 } | |
534 else if (body == LOG_LEVEL_TRACE) | |
535 { | |
536 Logging::EnableInfoLevel(true); | |
537 Logging::EnableTraceLevel(true); | |
538 } | |
539 else | |
540 { | |
541 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
542 "The log level must be one of the following values: \"" + | |
543 std::string(LOG_LEVEL_DEFAULT) + "\", \"" + | |
544 std::string(LOG_LEVEL_VERBOSE) + "\", of \"" + | |
545 std::string(LOG_LEVEL_TRACE) + "\""); | |
546 } | |
547 | |
548 // Success | 508 // Success |
549 LOG(WARNING) << "REST API call has switched the log level to: " << body; | 509 LOG(WARNING) << "REST API call has switched the log level to: " << body; |
550 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | 510 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
551 } | 511 } |
552 | 512 |