# HG changeset patch # User Sebastien Jodogne # Date 1581697348 -3600 # Node ID ea8c1c0e81ebab38e105b5caca6ca4beb047f51a # Parent 3c4269229566fc9ebb56dbb0ae382e71492ed3d2 Fix issue #65 (Logging improvements) diff -r 3c4269229566 -r ea8c1c0e81eb Core/HttpServer/HttpServer.cpp --- a/Core/HttpServer/HttpServer.cpp Fri Feb 14 14:56:06 2020 +0100 +++ b/Core/HttpServer/HttpServer.cpp Fri Feb 14 17:22:28 2020 +0100 @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -968,10 +969,15 @@ throw OrthancException(ErrorCode_BadParameterType, "Syntax error in some user-supplied data"); } + catch (boost::filesystem::filesystem_error& e) + { + throw OrthancException(ErrorCode_InternalError, + "Error while accessing the filesystem: " + e.path1().string()); + } catch (std::runtime_error&) { - // Presumably an error while parsing the JSON body - throw OrthancException(ErrorCode_BadRequest); + throw OrthancException(ErrorCode_BadRequest, + "Presumably an error while parsing the JSON body"); } catch (std::bad_alloc&) { diff -r 3c4269229566 -r ea8c1c0e81eb NEWS --- a/NEWS Fri Feb 14 14:56:06 2020 +0100 +++ b/NEWS Fri Feb 14 17:22:28 2020 +0100 @@ -7,8 +7,9 @@ * API version has been upgraded to 5 * added "/peers/{id}/system" route to test the connectivity with a remote peer (and eventually retrieve its version number) -* "/changes": Allow the "limit" argument to be greater than 100 -* /instances/{id}/preview route now takes the windowing into account +* /changes: Allow the "limit" argument to be greater than 100 +* /instances/{id}/preview: Now takes the windowing into account +* /tools/log-level: Possibility to access and change the log level without restarting Orthanc Plugins ------- @@ -21,6 +22,7 @@ * Support of MPEG4 transfer syntaxes in C-Store SCP * C-Find SCU at Instance level now sets the 0008,0052 tag to IMAGE per default (was INSTANCE). Therefore, the "ClearCanvas" and "Dcm4Chee" modality manufacturer have now been deprecated. +* Fix issue #65 (Logging improvements) * Fix issue #156 (Chunked Dicom-web transfer uses 100% CPU) * Fix issue #165 (Boundary parameter in multipart Content-Type is too long) * Fix issue #166 (CMake find_boost version is now broken with newer boost/cmake) diff -r 3c4269229566 -r ea8c1c0e81eb OrthancServer/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Fri Feb 14 14:56:06 2020 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Fri Feb 14 17:22:28 2020 +0100 @@ -42,6 +42,11 @@ #include "../ServerContext.h" +static const char* LOG_LEVEL_DEFAULT = "default"; +static const char* LOG_LEVEL_VERBOSE = "verbose"; +static const char* LOG_LEVEL_TRACE = "trace"; + + namespace Orthanc { // System information ------------------------------------------------------- @@ -490,6 +495,62 @@ } + static void GetLogLevel(RestApiGetCall& call) + { + std::string s; + + if (Logging::IsTraceLevelEnabled()) + { + s = LOG_LEVEL_TRACE; + } + else if (Logging::IsInfoLevelEnabled()) + { + s = LOG_LEVEL_VERBOSE; + } + else + { + s = LOG_LEVEL_DEFAULT; + } + + call.GetOutput().AnswerBuffer(s, MimeType_PlainText); + } + + + static void PutLogLevel(RestApiPutCall& call) + { + std::string body; + call.BodyToString(body); + + if (body == LOG_LEVEL_DEFAULT) + { + Logging::EnableInfoLevel(false); + Logging::EnableTraceLevel(false); + } + else if (body == LOG_LEVEL_VERBOSE) + { + Logging::EnableInfoLevel(true); + Logging::EnableTraceLevel(false); + } + else if (body == LOG_LEVEL_TRACE) + { + Logging::EnableInfoLevel(true); + Logging::EnableTraceLevel(true); + } + else + { + throw OrthancException(ErrorCode_ParameterOutOfRange, + "The log level must be one of the following values: \"" + + std::string(LOG_LEVEL_DEFAULT) + "\", \"" + + std::string(LOG_LEVEL_VERBOSE) + "\", of \"" + + std::string(LOG_LEVEL_TRACE) + "\""); + } + + // Success + LOG(WARNING) << "REST API call has switched the log level to: " << body; + call.GetOutput().AnswerBuffer("", MimeType_PlainText); + } + + void OrthancRestApi::RegisterSystem() { Register("/", ServeRoot); @@ -505,6 +566,8 @@ Register("/tools/metrics", GetMetricsEnabled); Register("/tools/metrics", PutMetricsEnabled); Register("/tools/metrics-prometheus", GetMetricsPrometheus); + Register("/tools/log-level", GetLogLevel); + Register("/tools/log-level", PutLogLevel); Register("/plugins", ListPlugins); Register("/plugins/{id}", GetPlugin); diff -r 3c4269229566 -r ea8c1c0e81eb TODO --- a/TODO Fri Feb 14 14:56:06 2020 +0100 +++ b/TODO Fri Feb 14 17:22:28 2020 +0100 @@ -193,3 +193,31 @@ * Create REST bindings with Slicer * Create REST bindings with Horos/OsiriX + + +==== +Misc +==== + +------- +Logging +------- + +This is a wish expressed in issue #65 on BitBucket: + +"Different levels for various modules (nice to have) + +We often need to debug DICOM interactions and logs are 'polluted' by +logs from the Rest API, i.e: since I have a process calling the +/changes route every 5 second, I'm lost in 17000 /changes record in my +logs everyday while I just want to check what kind of C-Find requests +are issued by a modality. If we go for it, logs could be configured +via the configuration file: i.e.: + +{ + "Web": "info", + "Dicom": "debug", + "Db": "warning", + "WebViewer": "warning", // here WebViewer is a plugin + "Generic": "warning", // for all stuffs we could not port to the new logging API or old plugins .... +}"