调试Android源码时打开ALOGV日志

 20 #undef NDEBUG

 21 #define LOG_NDEBUG   0  //打开LOGV

 22 #include



在.cpp文件中,添加如上语句,即可打开ALOGV。


关于android中log的机制,可以查看其具体文件:

/system/core/include/log/log.h:

 46 /*
 47  * Normally we strip ALOGV (VERBOSE messages) from release builds.
 48  * You can modify this (for example with "#define LOG_NDEBUG 0"
 49  * at the top of your source file) to change that behavior.
 50  */
 51 #ifndef LOG_NDEBUG
 52 #ifdef NDEBUG
 53 #define LOG_NDEBUG 1
 54 #else
 55 #define LOG_NDEBUG 0
 56 #endif
 57 #endif
 58
 59 /*
 60  * This is the local tag used for the following simplified
 61  * logging macros.  You can change this preprocessor definition
 62  * before using the other macros to change the tag.
 63  */
 64 #ifndef LOG_TAG
 65 #define LOG_TAG NULL
 66 #endif


注意这里的“ifndef LOG_TAG”

其实意思就是如果没有定义这个宏,那么进行预处理时,到 #include ,就会把这个宏给定义了。把LOG_TAG定义为NULL。

所以,这个宏的管理范围是以编译的模块为单位的。

比如,我要打开Camera.cpp中所有的ALOGV,只要在Camera.cpp这个文件#include 之前,加上:

 20 #undef NDEBUG

 21 #define LOG_NDEBUG   0  //打开LOGV

 即可。也就是最上面那一段。


本质上来说,C++的预编译宏的原理,可以理解为在代码编译之前,根据有意义的语句(宏语句)对你的源码进行自动化的处理(宏展开)。

这样来看,就很清楚了。只要找到具体的ALOGI实现的位置,就能很好的理解了。


你可能感兴趣的:(Android开发)