You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by do...@apache.org on 2019/06/19 09:16:52 UTC

[incubator-weex] branch master updated: [Android] Disable all log level in release app and enable log level above debug app. (#2581)

This is an automated email from the ASF dual-hosted git repository.

dongyayun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a7f46f  [Android] Disable all log level in release app and enable log level above debug app. (#2581)
2a7f46f is described below

commit 2a7f46f21a5a47d79dc99fc1d79acc7d4659ec0c
Author: YorkShen <sh...@gmail.com>
AuthorDate: Wed Jun 19 17:16:46 2019 +0800

    [Android] Disable all log level in release app and enable log level above debug app. (#2581)
    
    * Change log behaviour in subprocess
    
    1. Add a variable (DebugMode) in namespace of WeexCore. Sub-process and main-process would WeexCore::DebugMode separately.
    2. The default log out is enable only if WeexCore::DebugMode is true.
    3. As for LOGD printed before sub-process setting WeexCore::DebugMode, just delete -DDEBUG=1 in CMAKE
    
    * Set WeexCore::DebugMode in AddOption for better performance.
---
 weex_core/Source/CMakeLists.txt                    |  1 -
 .../android/jsengine/object/weex_global_object.cpp |  2 +-
 weex_core/Source/base/log_defines.cpp              | 47 ++++++++++++++++------
 weex_core/Source/base/log_defines.h                |  3 +-
 weex_core/Source/base/utils/log_utils.cpp          |  4 --
 weex_core/Source/base/utils/log_utils.h            |  3 --
 weex_core/Source/core/config/core_environment.cpp  |  2 +
 7 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt
index 8413a6c..22d8edc 100644
--- a/weex_core/Source/CMakeLists.txt
+++ b/weex_core/Source/CMakeLists.txt
@@ -31,7 +31,6 @@ add_compile_options(-fexceptions)
 
 add_definitions(-DGNU_SUPPORT=1)
 add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT=1)
-add_definitions(-DDEBUG=1)
 
 add_definitions(-DRENDER_LOG=0)
 add_definitions(-DPERFORMANCE_LOG=0)
diff --git a/weex_core/Source/android/jsengine/object/weex_global_object.cpp b/weex_core/Source/android/jsengine/object/weex_global_object.cpp
index 3474ce2..3345962 100644
--- a/weex_core/Source/android/jsengine/object/weex_global_object.cpp
+++ b/weex_core/Source/android/jsengine/object/weex_global_object.cpp
@@ -190,7 +190,7 @@ void WeexGlobalObject::initWxEnvironment(std::vector<INIT_FRAMEWORK_PARAMS *> &p
         // --------------------------------------------------------
         // add for debug mode
         if (String("debugMode") == type && String("true") == value) {
-            Weex::LogUtil::setDebugMode(true);
+            WeexCore::DebugMode = true;
         }
         // --------------------------------------------------------
 
diff --git a/weex_core/Source/base/log_defines.cpp b/weex_core/Source/base/log_defines.cpp
index 7991d27..6391736 100644
--- a/weex_core/Source/base/log_defines.cpp
+++ b/weex_core/Source/base/log_defines.cpp
@@ -28,7 +28,8 @@
 #include "core/manager/weex_core_manager.h"
 
 namespace WeexCore {
-    
+    bool DebugMode = false;
+
     struct LogFlattenHelper {
         LogFlattenHelper() : mLargeBuf() {}
         LogFlattenHelper(const char *fmt, va_list args) : LogFlattenHelper() {
@@ -85,21 +86,43 @@ namespace WeexCore {
         else {
             // Log to console by default
 #ifdef __ANDROID__
-            switch (level) {
-                case LogLevel::Error:
-                    __android_log_print(ANDROID_LOG_ERROR, tag, "%s:%lu, %s", file, line, log.str());
+            if(DebugMode) {
+                switch (level) {
+                    case LogLevel::Error:
+                        __android_log_print(ANDROID_LOG_ERROR,
+                                            tag,
+                                            "%s:%lu, %s",
+                                            file,
+                                            line,
+                                            log.str());
                     break;
-                case LogLevel::Warn:
-                    __android_log_print(ANDROID_LOG_WARN, tag, "%s:%lu, %s", file, line, log.str());
+                    case LogLevel::Warn:
+                        __android_log_print(ANDROID_LOG_WARN,
+                                            tag,
+                                            "%s:%lu, %s",
+                                            file,
+                                            line,
+                                            log.str());
                     break;
-                case LogLevel::Info:
-                    __android_log_print(ANDROID_LOG_INFO, tag, "%s:%lu, %s", file, line, log.str());
-                    break;
-                case LogLevel::Debug:
-                    __android_log_print(ANDROID_LOG_DEBUG, tag, "%s:%lu, %s", file, line, log.str());
+                    case LogLevel::Info:
+                        __android_log_print(ANDROID_LOG_INFO,
+                                            tag,
+                                            "%s:%lu, %s",
+                                            file,
+                                            line,
+                                            log.str());
                     break;
-                default:
+                    case LogLevel::Debug:
+                        __android_log_print(ANDROID_LOG_DEBUG,
+                                            tag,
+                                            "%s:%lu, %s",
+                                            file,
+                                            line,
+                                            log.str());
                     break;
+                    default:
+                        break;
+                }
             }
 #elif __APPLE__
             switch (level) {
diff --git a/weex_core/Source/base/log_defines.h b/weex_core/Source/base/log_defines.h
index 3651311..0776494 100644
--- a/weex_core/Source/base/log_defines.h
+++ b/weex_core/Source/base/log_defines.h
@@ -31,7 +31,8 @@ namespace WeexCore {
     };
     
     void PrintLog(LogLevel level, const char* tag, const char* file, unsigned long line, const char* format, ...);
-    
+
+    extern bool DebugMode;
 }
 
 #if defined(LOGE)
diff --git a/weex_core/Source/base/utils/log_utils.cpp b/weex_core/Source/base/utils/log_utils.cpp
index d5e1acb..019c20c 100644
--- a/weex_core/Source/base/utils/log_utils.cpp
+++ b/weex_core/Source/base/utils/log_utils.cpp
@@ -20,10 +20,6 @@
 #include "base/utils/log_utils.h"
 
 namespace Weex{
-  bool LogUtil::mDebugMode = false;
-  void LogUtil::setDebugMode(bool debug){
-    mDebugMode = debug;
-  }
   void LogUtil::ConsoleLogPrint(int level, const char* tag, const char* log) {
         // Log = 1, 
         // Warning = 2,
diff --git a/weex_core/Source/base/utils/log_utils.h b/weex_core/Source/base/utils/log_utils.h
index 3574123..f4487ca 100644
--- a/weex_core/Source/base/utils/log_utils.h
+++ b/weex_core/Source/base/utils/log_utils.h
@@ -29,10 +29,7 @@
 
 namespace Weex {
   class LogUtil {
-    private:
-      static bool mDebugMode;
     public:
-      static void setDebugMode(bool debug);
       static void ConsoleLogPrint(int level, const char* tag, const char* log);
   };
 }
diff --git a/weex_core/Source/core/config/core_environment.cpp b/weex_core/Source/core/config/core_environment.cpp
index 152682f..2b89c22 100644
--- a/weex_core/Source/core/config/core_environment.cpp
+++ b/weex_core/Source/core/config/core_environment.cpp
@@ -82,6 +82,8 @@ namespace WeexCore {
     mOptions.insert(std::pair<std::string, std::string>(key, value));
     if (key == "switchInteractionLog") {
       mInteractionLogSwitch = "true" == value;
+    } else if(key == "debugMode" && value == "true"){
+      WeexCore::DebugMode = true;
     }
   }