changeset 3673:3e68c3b4e3df storage-commitment

integration mainline->storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Feb 2020 17:55:53 +0100
parents e64432336055 (current diff) ea8c1c0e81eb (diff)
children 9201a7858cce
files NEWS
diffstat 5 files changed, 117 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/HttpServer.cpp	Fri Feb 14 09:05:06 2020 +0100
+++ b/Core/HttpServer/HttpServer.cpp	Fri Feb 14 17:55:53 2020 +0100
@@ -61,6 +61,7 @@
 #include <string.h>
 #include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/filesystem.hpp>
 #include <iostream>
 #include <string.h>
 #include <stdio.h>
@@ -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&)
         {
--- a/Core/Images/PixelTraits.h	Fri Feb 14 09:05:06 2020 +0100
+++ b/Core/Images/PixelTraits.h	Fri Feb 14 17:55:53 2020 +0100
@@ -383,6 +383,20 @@
     }
     
     ORTHANC_FORCE_INLINE
+    static void SetMinValue(PixelType& target)
+    {
+      // std::numeric_limits<float>::lowest is not supported on
+      // all compilers (for instance, Visual Studio 9.0 2008)
+      target = -std::numeric_limits<float>::max();
+    }
+
+    ORTHANC_FORCE_INLINE
+    static void SetMaxValue(PixelType& target)
+    {
+      target = std::numeric_limits<float>::max();
+    }
+
+    ORTHANC_FORCE_INLINE
     static void FloatToPixel(PixelType& target,
                              float value)
     {
--- a/NEWS	Fri Feb 14 09:05:06 2020 +0100
+++ b/NEWS	Fri Feb 14 17:55:53 2020 +0100
@@ -12,8 +12,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
 -------
@@ -27,6 +28,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)
--- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Fri Feb 14 09:05:06 2020 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Fri Feb 14 17:55:53 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);
--- a/TODO	Fri Feb 14 09:05:06 2020 +0100
+++ b/TODO	Fri Feb 14 17:55:53 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 ....
+}"