You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2019/07/04 14:03:24 UTC

[GitHub] [incubator-weex] darkThanBlack opened a new issue #2652: [iOS] WXLog will not disable NSLog in release mode automatically

darkThanBlack opened a new issue #2652: [iOS] WXLog will not disable NSLog in release mode automatically
URL: https://github.com/apache/incubator-weex/issues/2652
 
 
   ### Question
   
   If I called ``[WXLog setLogLevel: WXLogLevelAll]`` in somewhere, like ``appdelegate.m``, and just change target scheme build configuration from ``debug`` to ``release``, then there is still print the log to terminal.
   
   ### Reason
   
   Changing build configuration to ``debug`` means define ``DEBUG`` macro, but I have not see any condition judgment in ``WXLog.h`` and ``WXLog.m``. Unless user called ``WXLog`` like:
   
   ```
   #ifdef DEBUG
       [WXLog setLogLevel:WXLogLevelLog];
   #endif
   ```
   
   BUT many users will take it for granted that weex will block log by its self, just like these blog posts:[Weex开发 [iOS]](https://www.jianshu.com/p/e1ba1ffb755a).
   
   ### Source Code
   
   WXLog core macro like this:
   
   ```
   #define WX_LOG(flag, fmt, ...)          \
   do {                                    \
       [WXLog devLog:flag                     \
                file:WX_FILENAME              \
                line:__LINE__                 \
              format:(fmt), ## __VA_ARGS__];  \
   } while(0)
   ```
   
   One of Related WXLog core function like this:
   
   ```
   + (void)log:(WXLogFlag)flag file:(const char *)fileName line:(NSUInteger)line message:(NSString *)message {
       //other code...
   
       if ([WXLog logLevel] & flag) {
           NSLog(@"%@", logMessage);
       }
   }
   ```
   
   There is no treatment here. Probably developers have a responsibility to deal with WXLog, but I think at least there should be a description in documentation or somewhere.
   
   ===
   
   ### 问题描述
   
   如果用户在某处调用了类似``[WXLog setLogLevel: WXLogLevelAll]``的代码,然后只是简单地将
    target 的环境从``debug``模式改为``release``, ``WXLog``类依然会持续打印信息。
   
   ### 可能的原因
   
   target 的设置本质上是``DEBUG``宏的定义,我在``WXLog.h``和``WXLog.m``里面没有看到任何关于``DEBUG``的判断。这就意味着,除非用户自己在调用时进行判断:
   
   ```
   #ifdef DEBUG
       [WXLog setLogLevel:WXLogLevelLog];
   #endif
   ```
   
   不然``weex``自己还是会继续打印日志。但是鉴于``weex``是个有名的大项目,很多用户(例如我)下意识的会认为``weex``里面自己会有判断,就像这些新手教程里面写的一样:[Weex开发 [iOS]](https://www.jianshu.com/p/e1ba1ffb755a).
   
   ### 部分源码
   
   ``WXLog`` 主要的宏定义:
   
   ```
   #define WX_LOG(flag, fmt, ...)          \
   do {                                    \
       [WXLog devLog:flag                     \
                file:WX_FILENAME              \
                line:__LINE__                 \
              format:(fmt), ## __VA_ARGS__];  \
   } while(0)
   ```
   
   ``flag``指代打印级别,``weex``使用同一个系列的另外几个宏来打印日志,最后都会汇集到这里来。
   
   拿出一个类似的``WXLog``类方法实现来看:
   
   ```
   + (void)log:(WXLogFlag)flag file:(const char *)fileName line:(NSUInteger)line message:(NSString *)message {
       //other code...
   
       if ([WXLog logLevel] & flag) {
           NSLog(@"%@", logMessage);
       }
   }
   ```
   ``other code``主要都是对日志级别的一些判断,我暂时还未发现有涉及对``debug/release``模式的判断和控制。我并不认为框架开发者就应该来处理这种条件编译的问题,交由调用者来控制也完全说得通,但是不是至少可以在头文件注释或者文档里面提醒一下,一般开发都是在``debug``下来跑,``release``就可能直接打包,导致这个问题被略过。
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services