下面只是简单记录一下。
正文
第一步
引入头文件
#include <android/log.h>
第二步
预定义TAG和函数
#define TAG "BiuMall_" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
当然上面的就可以用了
LOGD("Hex dump at offset %ld (%zu bytes):", offset, len); LOGI("Hex dump at offset %ld (%zu bytes):", offset, len); LOGE("Hex dump at offset %ld (%zu bytes):", offset, len);
第三部
虽然上面的可以用了,但是之前的打印函数有一定的规则,以及需要控制日志输出等,因此重新转一下。
/* 输出日志控制 1 打印 0 不打印 */ static int debug_mode = 1; static int verbose_mode = 1;
适配之前的打印规则
/* Debug printing macro */ #define DEBUG(...) \ do { \ if (debug_mode) { \ LOGD(__VA_ARGS__); \ } \ } while (0) /* Verbose printing macro */ #define VERBOSE(...) \ do { \ if (verbose_mode || debug_mode) { \ LOGI(__VA_ARGS__); \ } \ } while (0) /* Error printing macro */ #define ERROR(...) \ do { \ LOGE(__VA_ARGS__); \ } while (0)
显示之前写的打印例子。
DEBUG("Device information for %s:", device_path); VERBOSE("Device information for %s:", device_path); ERROR("Device information for %s:", device_path);
重新编译即可。
参考文章
联系我们

微信号:rssme_com