changeset 4012:dc6e7c7372ae

merge
author Alain Mazy <alain@mazy.be>
date Mon, 08 Jun 2020 16:04:43 +0200
parents 914b15dedae3 (current diff) f0ee3f1db775 (diff)
children 1e9f6d706237
files Core/LoggingUtils.h
diffstat 5 files changed, 72 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Logging.cpp	Mon Jun 08 16:04:29 2020 +0200
+++ b/Core/Logging.cpp	Mon Jun 08 16:04:43 2020 +0200
@@ -164,65 +164,49 @@
     static bool globalTrace_ = false;
     
 #ifdef __EMSCRIPTEN__
-    static void defaultErrorLogFunc(const char* msg)
+    static void ErrorLogFunc(const char* msg)
     {
       emscripten_console_error(msg);
     }
 
-    static void defaultWarningLogFunc(const char* msg)
+    static void WarningLogFunc(const char* msg)
     {
       emscripten_console_warn(msg);
     }
 
-    static void defaultInfoLogFunc(const char* msg)
+    static void InfoLogFunc(const char* msg)
     {
       emscripten_console_log(msg);
     }
 
-    static void defaultTraceLogFunc(const char* msg)
+    static void TraceLogFunc(const char* msg)
     {
       emscripten_console_log(msg);
     }
 #else
 // __EMSCRIPTEN__ not #defined
-    static void defaultErrorLogFunc(const char* msg)
+    static void ErrorLogFunc(const char* msg)
     {
       fprintf(stderr, "E: %s\n", msg);
     }
 
-    static void defaultWarningLogFunc(const char*)
+    static void WarningLogFunc(const char*)
     {
       fprintf(stdout, "W: %s\n", msg);
     }
 
-    static void defaultInfoLogFunc(const char*)
+    static void InfoLogFunc(const char*)
     {
       fprintf(stdout, "I: %s\n", msg);
     }
 
-    static void defaultTraceLogFunc(const char*)
+    static void TraceLogFunc(const char*)
     {
       fprintf(stdout, "T: %s\n", msg);
     }
 #endif 
 // __EMSCRIPTEN__
 
-    static LoggingFunction globalErrorLogFunc = defaultErrorLogFunc;
-    static LoggingFunction globalWarningLogFunc = defaultWarningLogFunc;
-    static LoggingFunction globalInfoLogFunc = defaultInfoLogFunc;
-    static LoggingFunction globalTraceLogFunc = defaultTraceLogFunc;
-
-    void SetErrorWarnInfoTraceLoggingFunctions(LoggingFunction errorLogFunc,
-                                               LoggingFunction warningLogfunc,
-                                               LoggingFunction infoLogFunc,
-                                               LoggingFunction traceLogFunc)
-    {
-      globalErrorLogFunc = errorLogFunc;
-      globalWarningLogFunc = warningLogfunc;
-      globalInfoLogFunc = infoLogFunc;
-      globalTraceLogFunc = traceLogFunc;
-    }
-
     InternalLogger::InternalLogger(LogLevel level,
                                    const char* file  /* ignored */,
                                    int line  /* ignored */) :
@@ -739,9 +723,11 @@
     InternalLogger::InternalLogger(LogLevel level,
                                    const char* file,
                                    int line) : 
-      lock_(loggingMutex_), 
+      lock_(loggingMutex_, boost::defer_lock_t()), 
       stream_(&null_)  // By default, logging to "/dev/null" is simulated
     {
+      lock_.lock();
+      
       if (loggingContext_.get() == NULL)
       {
         fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine\n");
--- a/Core/Logging.h	Mon Jun 08 16:04:29 2020 +0200
+++ b/Core/Logging.h	Mon Jun 08 16:04:43 2020 +0200
@@ -101,14 +101,6 @@
 
     ORTHANC_PUBLIC void SetTargetFolder(const std::string& path);
 
-#if ORTHANC_ENABLE_LOGGING_STDIO == 1
-    typedef void (*LoggingFunction)(const char*);
-    ORTHANC_PUBLIC void SetErrorWarnInfoTraceLoggingFunctions(LoggingFunction errorLogFunc,
-                                                              LoggingFunction warningLogfunc,
-                                                              LoggingFunction infoLogFunc,
-                                                              LoggingFunction traceLogFunc);
-#endif
-
     struct NullStream : public std::ostream 
     {
       NullStream() : 
--- a/Core/LoggingUtils.h	Mon Jun 08 16:04:29 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-#include <sstream>
-#include <iostream>
-
-namespace Orthanc
-{
-  namespace Logging
-  {
-
-    /**
-      std::streambuf subclass used in FunctionCallingStream
-    */
-    template<typename T>
-    class FuncStreamBuf : public std::stringbuf
-    {
-    public:
-      FuncStreamBuf(T func) : func_(func) {}
-
-      virtual int sync()
-      {
-        std::string text = this->str();
-        const char* buf = text.c_str();
-        func_(buf);
-        this->str("");
-        return 0;
-      }
-    private:
-      T func_;
-    };
-  }
-}
\ No newline at end of file
--- a/OrthancServer/main.cpp	Mon Jun 08 16:04:29 2020 +0200
+++ b/OrthancServer/main.cpp	Mon Jun 08 16:04:43 2020 +0200
@@ -1624,6 +1624,37 @@
 
     LOG(WARNING) << "Orthanc version: " << version;
     assert(DisplayPerformanceWarning());
+
+    std::string s = "Architecture: ";
+    if (sizeof(void*) == 4)
+    {
+      s += "32-bit, ";
+    }
+    else if (sizeof(void*) == 8)
+    {
+      s += "64-bit, ";
+    }
+    else
+    {
+      s += "unsupported pointer size, ";
+    }
+
+    switch (Toolbox::DetectEndianness())
+    {
+      case Endianness_Little:
+        s += "little endian";
+        break;
+      
+      case Endianness_Big:
+        s += "big endian";
+        break;
+      
+      default:
+        s += "unsupported endianness";
+        break;
+    }
+    
+    LOG(INFO) << s;
   }
 
   int status = 0;
--- a/UnitTestsSources/LoggingTests.cpp	Mon Jun 08 16:04:29 2020 +0200
+++ b/UnitTestsSources/LoggingTests.cpp	Mon Jun 08 16:04:43 2020 +0200
@@ -41,7 +41,6 @@
 #include <sstream>
 
 #include "../Core/Logging.h"
-#include "../Core/LoggingUtils.h"
 
 using namespace Orthanc::Logging;
 
@@ -64,19 +63,19 @@
 }
 
 /**
-Extracts the log line payload
+   Extracts the log line payload
 
-"E0423 16:55:43.001194 LoggingTests.cpp:102] Foo bar?\n"
--->
-"Foo bar"
+   "E0423 16:55:43.001194 LoggingTests.cpp:102] Foo bar?\n"
+   -->
+   "Foo bar"
 
-If the log line cannot be matched, the function returns false.
+   If the log line cannot be matched, the function returns false.
 */
 
 #define EOLSTRING "\n"
 
 static bool GetLogLinePayload(std::string& payload,
-  const std::string& logLine)
+                              const std::string& logLine)
 {
   const char* regexStr = "[A-Z][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} "
     "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)" EOLSTRING "$";
@@ -100,6 +99,7 @@
   }
 }
 
+
 namespace
 {
   class LoggingMementoScope
@@ -114,8 +114,31 @@
       Orthanc::Logging::Reset();
     }
   };
+
+
+  /**
+   * std::streambuf subclass used in FunctionCallingStream
+   **/
+  template<typename T>
+  class FuncStreamBuf : public std::stringbuf
+  {
+  public:
+    FuncStreamBuf(T func) : func_(func) {}
+
+    virtual int sync()
+    {
+      std::string text = this->str();
+      const char* buf = text.c_str();
+      func_(buf);
+      this->str("");
+      return 0;
+    }
+  private:
+    T func_;
+  };
 }
 
+
 TEST(FuncStreamBuf, BasicTest)
 {
   LoggingMementoScope loggingConfiguration;