android c++添加log 与 头文件查找

1、c++添加log

__android_log_print(prio, tag, __VA_ARGS)函数的实现:

int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
  ErrnoRestorer errno_restorer;

  if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
    return -EPERM;
  }

  va_list ap; 
  char buf[LOG_BUF_SIZE];

  va_start(ap, fmt);
  vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
  va_end(ap);

  __android_log_message log_message = { 
      sizeof(__android_log_message), LOG_ID_MAIN, prio, tag, nullptr, 0, buf};
  __android_log_write_log_message(&log_message);
  return 1;
} 

__android_log_print函数的具体实现不用太过关系,观察下常用的打印log如ALOGE等。

#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) --->

#define ALOG(priority, tag, ...) LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) - -->

#define LOG_PRI(priority, tag, ...) android_printLog(priority, tag, __VA_ARGS__) --->

#define android_printLog(prio, tag, ...) __android_log_print(prio, tag, __VA_ARGS__)

上层调用来说,我们可以直接建立ALOGE与__android_log_print之间的关系,并且如下的使用:

#include LOG_TAG
#undef LOG_TAG
#endif

#define LOG_TAG "lethe_DEBUG"
#include <android/log.h>    // 在此处等价于 #include<utils/Log.h>
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,## __VA_ARGS__)
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG, ## __VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG, ## __VA_ARGS__)

fun()
{
        ALOGE("debug log");
}

2、头文件查找

见到一些#include <android/log.h>

这种的头文件可以在framework/system等目录下进行查找,如 android/log.h 定义是在:

system/core/include/android/log.h

见到#include<hidl/memory/1.0/IMemory.h>头文件,hidl与aidl等会生成大量的中间件,可以在out/soong/.intermediates目录下进行查找,该文件定义在:

out/soong/.intermediates/system/libhidl/transport/memory/1.0/android.hidl.memory@1.0_genc++_headers/gen/android/hidl/memory/1.0/IMemory.h

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值