changeset 4268:0ae2ca210077

new macro TLOG() to replace VLOG() for trace logs with a category
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Nov 2020 14:48:15 +0100
parents a20928107a90
children c7bd2f21ccc3
files OrthancFramework/Sources/Cache/MemoryCache.cpp OrthancFramework/Sources/DicomParsing/DicomModification.cpp OrthancFramework/Sources/HttpServer/HttpServer.cpp OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp OrthancFramework/Sources/Logging.cpp OrthancFramework/Sources/Logging.h OrthancFramework/Sources/SQLite/Connection.cpp OrthancFramework/Sources/SQLite/Statement.cpp OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/OrthancGetRequestHandler.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp
diffstat 14 files changed, 63 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Cache/MemoryCache.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/Cache/MemoryCache.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -35,7 +35,7 @@
       Page* p = NULL;
       if (index_.Contains(id, p))
       {
-        VLOG(1) << "Reusing a cache page";
+        LOG(TRACE) << "Reusing a cache page";
         assert(p != NULL);
         index_.MakeMostRecent(id);
         return *p;
@@ -45,7 +45,7 @@
       // is full.
       if (index_.GetSize() == cacheSize_)
       {
-        VLOG(1) << "Dropping the oldest cache page";
+        LOG(TRACE) << "Dropping the oldest cache page";
         index_.RemoveOldest(p);
         delete p;
       }
@@ -56,7 +56,7 @@
       result->content_.reset(provider_.Provide(id));
 
       // Add the newly create page to the cache
-      VLOG(1) << "Registering new data in a cache page";
+      LOG(TRACE) << "Registering new data in a cache page";
       p = result.release();
       index_.Add(id, p);
       return *p;
@@ -74,7 +74,7 @@
       Page* p = NULL;
       if (index_.Contains(id, p))
       {
-        VLOG(1) << "Invalidating a cache page";
+        LOG(TRACE) << "Invalidating a cache page";
         assert(p != NULL);
         delete p;
         index_.Invalidate(id);
--- a/OrthancFramework/Sources/DicomParsing/DicomModification.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/DicomParsing/DicomModification.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -1166,12 +1166,12 @@
       {
         case DicomModification::TagOperation_Keep:
           target.Keep(tag);
-          VLOG(1) << "Keep: " << name << " " << tag;
+          LOG(TRACE) << "Keep: " << name << " " << tag;
           break;
 
         case DicomModification::TagOperation_Remove:
           target.Remove(tag);
-          VLOG(1) << "Remove: " << name << " " << tag;
+          LOG(TRACE) << "Remove: " << name << " " << tag;
           break;
 
         default:
@@ -1207,8 +1207,8 @@
 
       target.Replace(tag, value, false);
 
-      VLOG(1) << "Replace: " << name << " " << tag 
-              << " == " << value.toStyledString();
+      LOG(TRACE) << "Replace: " << name << " " << tag 
+                 << " == " << value.toStyledString();
     }
   }
 
--- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -1088,7 +1088,7 @@
 
       std::transform(name.begin(), name.end(), name.begin(), ::tolower);
       headers.insert(std::make_pair(name, value));
-      VLOG(1) << "HTTP header: [" << name << "]: [" << value << "]";
+      LOG(TRACE) << "HTTP header: [" << name << "]: [" << value << "]";
     }
 
     if (server.IsHttpCompressionEnabled())
--- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -280,7 +280,7 @@
       }
       else
       {
-        VLOG(1) << "Job backup is not supported for job of type: " << jobType_;
+        LOG(TRACE) << "Job backup is not supported for job of type: " << jobType_;
         return false;
       }
     }
--- a/OrthancFramework/Sources/Logging.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/Logging.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -221,6 +221,7 @@
           break;
 
         case LogLevel_TRACE:
+          // TODO - Check trace category
           if (traceEnabled_)
           {
             TraceLogFunc(message.c_str());
@@ -643,10 +644,12 @@
 
 
     InternalLogger::InternalLogger(LogLevel level,
+                                   TraceCategory category,
                                    const char* file,
                                    int line) : 
       lock_(loggingStreamsMutex_, boost::defer_lock_t()),
       level_(level),
+      category_(category),
       stream_(&nullStream_)  // By default, logging to "/dev/null" is simulated
     {
       if (pluginContext_ != NULL)
@@ -670,7 +673,7 @@
         // We are logging in a standalone application, not inside an Orthanc plugin
 
         if ((level == LogLevel_INFO  && !infoEnabled_) ||
-            (level == LogLevel_TRACE && !traceEnabled_))
+            (level == LogLevel_TRACE && !traceEnabled_))     // TODO - Check trace category
         {
           // This logging level is disabled, directly exit as the
           // stream is set to "/dev/null"
--- a/OrthancFramework/Sources/Logging.h	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/Logging.h	Mon Nov 02 14:48:15 2020 +0100
@@ -51,6 +51,13 @@
       LogLevel_INFO,
       LogLevel_TRACE
     };
+
+    enum TraceCategory
+    {
+      TraceCategory_GENERIC,
+      TraceCategory_SQLITE,
+      TraceCategory_DICOM
+    };
     
     ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level);
 
@@ -97,14 +104,26 @@
 }
 
 
+
+/**
+ * NB: The macro "VLOG(unused)" is for backward compatibility with
+ * Orthanc <= 1.8.0.
+ **/
+
 #if ORTHANC_ENABLE_LOGGING != 1
-#  define LOG(level)   ::Orthanc::Logging::NullStream()
-#  define VLOG(level)  ::Orthanc::Logging::NullStream()
+#  define LOG(level)     ::Orthanc::Logging::NullStream()
+#  define VLOG(unused)   ::Orthanc::Logging::NullStream()
+#  define TLOG(category) ::Orthanc::Logging::NullStream()
 #else /* ORTHANC_ENABLE_LOGGING == 1 */
-#  define LOG(level)  ::Orthanc::Logging::InternalLogger        \
-  (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__)
-#  define VLOG(level) ::Orthanc::Logging::InternalLogger        \
-  (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__)
+#  define LOG(level)     ::Orthanc::Logging::InternalLogger             \
+  (::Orthanc::Logging::LogLevel_ ## level,                              \
+   ::Orthanc::Logging::TraceCategory_GENERIC, __FILE__, __LINE__)
+#  define VLOG(unused)   ::Orthanc::Logging::InternalLogger             \
+  (::Orthanc::Logging::LogLevel_TRACE,                                  \
+   ::Orthanc::Logging::TraceCategory_GENERIC, __FILE__, __LINE__)
+#  define TLOG(category) ::Orthanc::Logging::InternalLogger             \
+  (::Orthanc::Logging::LogLevel_TRACE,                                  \
+   ::Orthanc::Logging::TraceCategory_ ## category, __FILE__, __LINE__)
 #endif
 
 
@@ -125,13 +144,16 @@
     {
     private:
       LogLevel           level_;
+      TraceCategory      category_;
       std::stringstream  messageStream_;
 
     public:
       InternalLogger(LogLevel level,
+                     TraceCategory category,
                      const char* file  /* ignored */,
                      int line  /* ignored */) :
-        level_(level)
+        level_(level),
+        category_(category)
       {
       }
 
@@ -169,11 +191,13 @@
     private:
       boost::mutex::scoped_lock           lock_;
       LogLevel                            level_;
+      TraceCategory                       category_;
       std::unique_ptr<std::stringstream>  pluginStream_;
       std::ostream*                       stream_;
 
     public:
       InternalLogger(LogLevel level,
+                     TraceCategory category,
                      const char* file,
                      int line);
 
--- a/OrthancFramework/Sources/SQLite/Connection.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/SQLite/Connection.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -154,7 +154,7 @@
     bool Connection::Execute(const char* sql) 
     {
 #if ORTHANC_SQLITE_STANDALONE != 1
-      VLOG(1) << "SQLite::Connection::Execute " << sql;
+      TLOG(SQLITE) << "SQLite::Connection::Execute " << sql;
 #endif
 
       CheckIsOpen();
@@ -385,7 +385,7 @@
     void Connection::FlushToDisk()
     {
 #if ORTHANC_SQLITE_STANDALONE != 1
-      VLOG(1) << "SQLite::Connection::FlushToDisk";
+      TLOG(SQLITE) << "SQLite::Connection::FlushToDisk";
 #endif
 
       int err = sqlite3_wal_checkpoint(db_, NULL);
--- a/OrthancFramework/Sources/SQLite/Statement.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancFramework/Sources/SQLite/Statement.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -59,8 +59,8 @@
 #else
 // Trace logging is enabled in debug builds
 #  include "../Logging.h"
-#  define LOG_CREATE(message)  VLOG(1) << "SQLite::Statement create: " << message;
-#  define LOG_APPLY(message);  // VLOG(1) << "SQLite::Statement apply: " << message;
+#  define LOG_CREATE(message)  TLOG(SQLITE) << "SQLite::Statement create: " << message;
+#  define LOG_APPLY(message);  // TLOG(SQLITE) << "SQLite::Statement apply: " << message;
 #endif
 
 #include "sqlite3.h"
@@ -168,7 +168,7 @@
       // spurious error callback.
       if (clear_bound_vars)
         sqlite3_clear_bindings(GetStatement());
-      //VLOG(1) << "SQLite::Statement::Reset";
+      //TLOG(SQLITE) << "SQLite::Statement::Reset";
       sqlite3_reset(GetStatement());
     }
 
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -4661,7 +4661,7 @@
                                      _OrthancPluginService service,
                                      const void* parameters)
   {
-    VLOG(1) << "Calling service " << service << " from plugin " << plugin.GetPath();
+    LOG(TRACE) << "Calling service " << service << " from plugin " << plugin.GetPath();
 
     if (service == _OrthancPluginService_DatabaseAnswer)
     {
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -155,10 +155,9 @@
 
       virtual void Compute(SQLite::FunctionContext& context)
       {
-        VLOG(1) << "There exists a remaining ancestor with public ID \""
-                << context.GetStringValue(0)
-                << "\" of type "
-                << context.GetIntValue(1);
+        TLOG(SQLITE) << "There exists a remaining ancestor with public ID \""
+                     << context.GetStringValue(0) << "\" of type "
+                     << context.GetIntValue(1);
 
         if (!hasRemainingAncestor_ ||
             remainingType_ >= context.GetIntValue(1))
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -151,8 +151,8 @@
         if (pc->result == ASC_P_ACCEPTANCE &&
             LookupTransferSyntax(transferSyntax, pc->acceptedTransferSyntax))
         {
-          VLOG(0) << "C-GET SCP accepted: SOP class " << sopClassUid
-                  << " with transfer syntax " << GetTransferSyntaxUid(transferSyntax);
+          TLOG(DICOM) << "C-GET SCP accepted: SOP class " << sopClassUid
+                      << " with transfer syntax " << GetTransferSyntaxUid(transferSyntax);
           if (std::string(pc->abstractSyntax) == sopClassUid)
           {
             accepted[transferSyntax] = pc->presentationContextID;
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -1245,7 +1245,7 @@
          * just-created folders before the remote WebDAV has time to
          * write files into it.
          **/
-        VLOG(1) << "Cleaning up the empty WebDAV upload folders";
+        LOG(TRACE) << "Cleaning up the empty WebDAV upload folders";
         that->uploads_.RemoveEmptyFolders();
         lastModification = GetNow();
       }
--- a/OrthancServer/Sources/ServerContext.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -222,7 +222,7 @@
   {
     if (saveJobs_)
     {
-      VLOG(1) << "Serializing the content of the jobs engine";
+      LOG(TRACE) << "Serializing the content of the jobs engine";
     
       try
       {
--- a/OrthancServer/Sources/ServerIndex.cpp	Sun Nov 01 12:43:18 2020 +0100
+++ b/OrthancServer/Sources/ServerIndex.cpp	Mon Nov 02 14:48:15 2020 +0100
@@ -178,7 +178,7 @@
     virtual void SignalRemainingAncestor(ResourceType parentType,
                                          const std::string& publicId)
     {
-      VLOG(1) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
+      LOG(TRACE) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
 
       if (hasRemainingLevel_)
       {
@@ -205,9 +205,9 @@
 
     virtual void SignalChange(const ServerIndexChange& change)
     {
-      VLOG(1) << "Change related to resource " << change.GetPublicId() << " of type " 
-              << EnumerationToString(change.GetResourceType()) << ": " 
-              << EnumerationToString(change.GetChangeType());
+      LOG(TRACE) << "Change related to resource " << change.GetPublicId() << " of type " 
+                 << EnumerationToString(change.GetResourceType()) << ": " 
+                 << EnumerationToString(change.GetChangeType());
 
       if (insideTransaction_)
       {
@@ -1615,7 +1615,7 @@
         throw OrthancException(ErrorCode_FullStorage);
       }
       
-      VLOG(1) << "Recycling one patient";
+      LOG(TRACE) << "Recycling one patient";
       db_.DeleteResource(patientToRecycle);
 
       if (!IsRecyclingNeeded(instanceSize))