android,NDK, write logs to a file


I have this lines in my code (.c) :

#define LOGI(x...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG,x)#define LOGE(x...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,x)

I use them for outputing in LogCat, how to modify these lines to write messages to a file, or how can I get certain messages from LogCat in my code ? 



If this is for debugging purpose, I use this macro:

#define WRITE_LOG(s, ...) do { \FILE *f = fopen("/data/local/tmp/log.txt", "a+"); \  fprintf(f, s, __VA_ARGS__); \  fflush(f); \  fclose(f); \} while (0)

It has the advantage of being totally independent from the Android SDK/NDK, which allows to debug native code without having to modify all your build system and includes in order to link on the logcat functions.

A small warning though: I've taken the habit of creating the file using touch /data/local/tmp/log.txtin adb-shell before launching the program, as in most cases the system prevents you from creating new files. And by the way, the location /data/local/tmp/ has the advantage of being accessible even without root privileges.





If you are under an application, you can use /data/data//

so dry lab:

FILE f = fopen("/data/data//", 'w');fprintf(f, "my message\n");fclose(f);

should work.


0 down vote

If you are under an application, you can use /data/data//

so dry lab:

FILE f = fopen("/data/data//", 'w');fprintf(f, "my message\n");fclose(f);

should work.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android自动化测试工具——Monkey
  2. Android的nodpi,xhdpi,hdpi,mdpi,ldpi
  3. Android中的四种布局
  4. android recover 系统代码分析 -- 选择进
  5. 2020最新Android大厂面试真题大全(附答案)
  6. android横竖屏总结
  7. Android下 读写文件
  8. 搭建Android的开发环境
  9. 学习Android(安卓)Handler消息传递机制
  10. android layout_weight的使用