diff Core/Logging.cpp @ 4017:c783f4f29390

log using emscripten
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Jun 2020 18:15:31 +0200
parents 27628b0f6ada
children 05a363186da6
line wrap: on
line diff
--- a/Core/Logging.cpp	Mon Jun 08 17:20:32 2020 +0200
+++ b/Core/Logging.cpp	Mon Jun 08 18:15:31 2020 +0200
@@ -163,8 +163,8 @@
 {
   namespace Logging
   {
-    static bool globalVerbose_ = false;
-    static bool globalTrace_ = false;
+    static bool infoEnabled_ = false;
+    static bool traceEnabled_ = false;
     
 #ifdef __EMSCRIPTEN__
     static void ErrorLogFunc(const char* msg)
@@ -208,12 +208,6 @@
     }
 #endif  /* __EMSCRIPTEN__ */
 
-    InternalLogger::InternalLogger(LogLevel level,
-                                   const char* file  /* ignored */,
-                                   int line  /* ignored */) :
-      level_(level)
-    {
-    }
 
     InternalLogger::~InternalLogger()
     {
@@ -222,25 +216,25 @@
       switch (level_)
       {
         case LogLevel_ERROR:
-          globalErrorLogFunc(message.c_str());
+          ErrorLogFunc(message.c_str());
           break;
 
         case LogLevel_WARNING:
-          globalWarningLogFunc(message.c_str());
+          WarningLogFunc(message.c_str());
           break;
 
         case LogLevel_INFO:
-          if (globalVerbose_)
+          if (infoEnabled_)
           {
-            globalInfoLogFunc(message.c_str());
+            InfoLogFunc(message.c_str());
             // TODO: stone_console_info(message_.c_str());
           }
           break;
 
         case LogLevel_TRACE:
-          if (globalTrace_)
+          if (traceEnabled_)
           {
-            globalTraceLogFunc(message.c_str());
+            TraceLogFunc(message.c_str());
           }
           break;
 
@@ -249,7 +243,7 @@
           std::stringstream ss;
           ss << "Unknown log level (" << level_ << ") for message: " << message;
           std::string s = ss.str();
-          globalErrorLogFunc(s.c_str());
+          ErrorLogFunc(s.c_str());
         }
       }
     }
@@ -276,22 +270,28 @@
 
     void EnableInfoLevel(bool enabled)
     {
-      globalVerbose_ = enabled;
+      infoEnabled_ = enabled;
+
+      if (!enabled)
+      {
+        // Also disable the "TRACE" level when info-level debugging is disabled
+        traceEnabled_ = false;
+      }
     }
 
     bool IsInfoLevelEnabled()
     {
-      return globalVerbose_;
+      return infoEnabled_;
     }
 
     void EnableTraceLevel(bool enabled)
     {
-      globalTrace_ = enabled;
+      traceEnabled_ = enabled;
     }
 
     bool IsTraceLevelEnabled()
     {
-      return globalTrace_;
+      return traceEnabled_;
     }
 
     void SetTargetFile(const std::string& path)
@@ -760,8 +760,6 @@
               break;
 
             case LogLevel_WARNING:
-              printf("[%s]\n", message.c_str());
-        
               pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogWarning, message.c_str());
               break;