diff Core/Logging.cpp @ 3489:e7723a39adf8

Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger use an std::stringstream so that manipulators like "std::hex" are supported (when using ORTHANC_ENABLE_LOGGING_PLUGIN or ORTHANC_ENABLE_LOGGING_STDIO)
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 10 Aug 2019 13:40:08 +0200
parents a4f2354f04c3
children b2d4dd16dae8
line wrap: on
line diff
--- a/Core/Logging.cpp	Mon Aug 05 13:57:54 2019 +0200
+++ b/Core/Logging.cpp	Sat Aug 10 13:40:08 2019 +0200
@@ -92,6 +92,7 @@
  *********************************************************/
 
 #include <boost/lexical_cast.hpp>
+#include <sstream>
 
 namespace Orthanc
 {
@@ -113,20 +114,21 @@
 
     InternalLogger::~InternalLogger()
     {
+      std::string message = messageStream_.str();
       if (context_ != NULL)
       {
         switch (level_)
         {
           case InternalLevel_ERROR:
-            OrthancPluginLogError(context_, message_.c_str());
+            OrthancPluginLogError(context_, message.c_str());
             break;
 
           case InternalLevel_WARNING:
-            OrthancPluginLogWarning(context_, message_.c_str());
+            OrthancPluginLogWarning(context_, message.c_str());
             break;
 
           case InternalLevel_INFO:
-            OrthancPluginLogInfo(context_, message_.c_str());
+            OrthancPluginLogInfo(context_, message.c_str());
             break;
 
           case InternalLevel_TRACE:
@@ -136,7 +138,7 @@
           default:
           {
             std::string s = ("Unknown log level (" + boost::lexical_cast<std::string>(level_) +
-                             ") for message: " + message_);
+                             ") for message: " + message);
             OrthancPluginLogError(context_, s.c_str());
             break;
           }
@@ -239,20 +241,22 @@
 
     InternalLogger::~InternalLogger()
     {
+      std::string message = messageStream_.str();
+
       switch (level_)
       {
         case InternalLevel_ERROR:
-          globalErrorLogFunc(message_.c_str());
+          globalErrorLogFunc(message.c_str());
           break;
 
         case InternalLevel_WARNING:
-          globalWarningLogFunc(message_.c_str());
+          globalWarningLogFunc(message.c_str());
           break;
 
         case InternalLevel_INFO:
           if (globalVerbose_)
           {
-            globalInfoLogFunc(message_.c_str());
+            globalInfoLogFunc(message.c_str());
             // TODO: stone_console_info(message_.c_str());
           }
           break;
@@ -260,14 +264,14 @@
         case InternalLevel_TRACE:
           if (globalTrace_)
           {
-            globalTraceLogFunc(message_.c_str());
+            globalTraceLogFunc(message.c_str());
           }
           break;
 
         default:
         {
           std::stringstream ss;
-          ss << "Unknown log level (" << level_ << ") for message: " << message_;
+          ss << "Unknown log level (" << level_ << ") for message: " << message;
           auto s = ss.str();
           globalErrorLogFunc(s.c_str());
         }