版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_29542611/article/details/84594590
Android NDK项目中C++文件中打印日志
工作需要,在NDK项目中的C++文件中打印日志,还是费了点劲查找 才达到自己 想要的效果了。
步骤
添加头文件
添加头文件 定义宏函数
#include <android/log.h>
//这2行可以不用添加,是博主 特定需求
#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
//"C_TAG"
//static const char* _CTagHead(char* file,const char* fun,char* line)
//{
// int len = strlen(file) + strlen(fun);
// char *buf = new char[64]{0};
// sprintf(buf,"%s:%s",file,fun);
// return buf;
//}
//#define LOG_TAG _CTagHead(__FILE__,__func__)
#define LOG_TAG "C_TAG"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
如何使用
这是博主的调用处
sprintf(buf,"bl_id=%s,height=%s",string_tools::pod_to_hex(bl_id).c_str() ,heightStr);
LOGD( "%s",buf );