android log使用
16lz
2021-01-24
#define LOG_NDEBUG 0#define LOG_NDDEBUG 0#define LOG_NIDEBUG 0#define LOG_NVDEBUG 0#define LOG_NWDEBUG 0#define VERY_VERBOSE_LOGGING
可以一次打开LOGV,LOGI,LOGD,也可以分别打开:
#undef NDEBUG //打开LOGV/LOGI/LOGD#define LOG_NDEBUG 0 //打开LOGV#define LOG_NIDEBUG 0 //打开LOGI#define LOG_NDDEBUG 0 //打开LOGD
举例
举例,如果要看AndroidRuntime的LOGI和LOGD,可以有这样2种写法:
方法一
NDEBUG-LOG_NDEBUG=LOG_NIDEBUG +LOG_NIDEBUG
#define LOG_TAG "AndroidRuntime"#undef NDEBUG#define LOG_NDEBUG 1#include <utils/Log.h>
方法二
LOG_NIDEBUG +LOG_NIDEBUG
#define LOG_TAG "AndroidRuntime"#define LOG_NIDEBUG 0#define LOG_NDDEBUG 0#include <utils/Log.h>
在Log.h(system/core/include/cutils)中,log相关宏定义如下:
#ifndef LOG_NDEBUG#ifdef NDEBUG#define LOG_NDEBUG 1#else#define LOG_NDEBUG 0#endif#endif#ifndef LOG_NIDEBUG#ifdef NDEBUG#define LOG_NIDEBUG 1#else#define LOG_NIDEBUG 0#endif#endif#ifndef LOG_NDDEBUG#ifdef NDEBUG#define LOG_NDDEBUG 1#else#define LOG_NDDEBUG 0#endif#endif#ifndef LOG_TAG#define LOG_TAG NULL#endif#ifndef LOG_PRI#define LOG_PRI(priority, tag, ...) / ({ / if (((priority == ANDROID_LOG_VERBOSE) && (LOG_NDEBUG == 0)) || / ((priority == ANDROID_LOG_DEBUG) && (LOG_NDDEBUG == 0)) || / ((priority == ANDROID_LOG_INFO) && (LOG_NIDEBUG == 0)) || / (priority == ANDROID_LOG_WARN) || / (priority == ANDROID_LOG_ERROR) || / (priority == ANDROID_LOG_FATAL)) / (void)android_printLog(priority, tag, __VA_ARGS__); / })#endif
所以,需要打印log时,第一要注意LOG_TAG要定义,第二,要注意LOGV(...)、 LOGD(...)、LOGI(...) 、LOGW(...) 、LOGE(...)对应的 LOG_NDEBUG 、LOG_NDDEBUG 、LOG_NIDEBUG 要定义为0。
例子如下:
要使用LOGI()必须定义如下内容
#define LOG_TAG "sysproc"#define LOG_NIDEBUG 0
更多相关文章
- Android(安卓)上使用library时xml使用自定义属性提示 error: Err
- android 网络连接 HttpGet HttpPost方法
- android Contentprovider配置记录
- Android(安卓)强制竖屏
- Android(安卓)Retrofit 入门教程
- Android(安卓)按power键唤醒屏幕流程
- Android(安卓)dialog 对话框自定义布局
- Fragment之间的跳转
- Android中常用的bitmap处理方法 (bitmap工具类)