changeset 7027:27fb4cb98985 streaming tip

--logs-threadnames-in-context
author Alain Mazy <am@orthanc.team>
date Thu, 16 Jul 2026 16:55:53 +0200
parents d251cd0ec90a
children
files NEWS OrthancFramework/Sources/Logging.cpp OrthancFramework/Sources/Logging.h OrthancServer/Sources/main.cpp
diffstat 4 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Jul 16 16:00:22 2026 +0200
+++ b/NEWS	Thu Jul 16 16:55:53 2026 +0200
@@ -41,6 +41,8 @@
   - Some line of log now contain additional contextual informations like the job id they relate to.
     A new "--logs-no-context" command line option can be used to get back to the previous behavior to
     keep backward compatibility and reduce the lines length.
+    Another "--logs-threadnames-in-context" command line option can be used to add more information in the 
+    contexts wrt the thread that has requested a service.  This is mainly for developers.
 * C-Find SCP:
   - When Orthanc was requested a sequence in a C-Find query, Orthanc was actually not returning
     any sequences in the C-Find answer if the matched resource did contain the requested sequence and
--- a/OrthancFramework/Sources/Logging.cpp	Thu Jul 16 16:00:22 2026 +0200
+++ b/OrthancFramework/Sources/Logging.cpp	Thu Jul 16 16:55:53 2026 +0200
@@ -46,8 +46,6 @@
 {
   namespace Logging
   {
-    static bool logCallerThreadNameInContext = false; // add a "from THREADNAME" in the context everytime the context is copied from a thread to the other to help track the runnable/callable journey
-
     static const uint32_t ALL_CATEGORIES_MASK = 0xffffffff;
     
     static uint32_t infoCategoriesMask_ = 0;
@@ -953,6 +951,7 @@
 static ThreadsInformations                      threadsInformations_;
 static bool                                     enableThreadNames_ = true;
 static bool                                     enableThreadContexts_ = true;
+static bool                                     logCallerThreadNameInContext_ = false; // add a "from THREADNAME" in the context everytime the context is copied from a thread to the other to help track the runnable/callable journey
 static std::list<Orthanc::Logging::ILoggingListener*> loggingListeners_;
 static boost::shared_mutex                            loggingListenersMutex_;
 
@@ -971,6 +970,11 @@
       enableThreadContexts_ = enabled;
     }
 
+    void SetThreadNamesInContextsEnabled(bool enabled)
+    {
+      logCallerThreadNameInContext_ = enabled;
+    }
+
     static void GetLogPath(boost::filesystem::path& log,
                            boost::filesystem::path& link,
                            const std::string& suffix,
@@ -1129,7 +1133,7 @@
     ThreadContextMemento::ScopedSetter::ScopedSetter(const ThreadContextMemento& memento) :
       count_(0)
     {
-      if (logCallerThreadNameInContext && enableThreadNames_ && !memento.pimpl_->threadName_.empty())
+      if (logCallerThreadNameInContext_ && enableThreadNames_ && !memento.pimpl_->threadName_.empty())
       {
         PushCurrentThreadContext("from " + memento.pimpl_->threadName_);
         count_++;
--- a/OrthancFramework/Sources/Logging.h	Thu Jul 16 16:00:22 2026 +0200
+++ b/OrthancFramework/Sources/Logging.h	Thu Jul 16 16:55:53 2026 +0200
@@ -139,6 +139,8 @@
 
     ORTHANC_PUBLIC void SetThreadContextsEnabled(bool enabled);
 
+    ORTHANC_PUBLIC void SetThreadNamesInContextsEnabled(bool enabled);
+
     ORTHANC_PUBLIC void SetCurrentThreadName(const std::string& name);
 
     ORTHANC_PUBLIC bool HasCurrentThreadName();
--- a/OrthancServer/Sources/main.cpp	Thu Jul 16 16:00:22 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Thu Jul 16 16:55:53 2026 +0200
@@ -756,6 +756,9 @@
     << "\t\t\t(if \"file\" is \"-\", dumps to stdout)" << std::endl
     << "  --errors\t\tprint the supported error codes and exit" << std::endl
     << "  --verbose\t\tbe verbose in logs" << std::endl
+    << "  --logs-no-thread\tto remove thread names from logs" << std::endl
+    << "  --logs-no-context\tto remove contexts from logs" << std::endl
+    << "  --logs-threadnames-in-context\t\tto add caller thread names in logs contexts" << std::endl
     << "  --trace\t\thighest verbosity in logs (for debug)" << std::endl
     << "  --upgrade\t\tallow Orthanc to upgrade the version of the" << std::endl
     << "\t\t\tdatabase (beware that the database will become" << std::endl
@@ -2075,6 +2078,10 @@
     {
       Logging::SetThreadContextsEnabled(false);
     }
+    else if (argument == "--logs-threadnames-in-context")
+    {
+      Logging::SetThreadNamesInContextsEnabled(true);
+    }
     else if (argument == "--trace")
     {
       SetGlobalVerbosity(Verbosity_Trace);