android,NDK, write logs to a file
来源:互联网 发布:商品标签制作软件 编辑:程序博客网 时间:2024/05/19 18:46
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.txt
in 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/<application name>/<file name>", 'w');fprintf(f, "my message\n");fclose(f);
should work.
If you are under an application, you can use /data/data//
so dry lab:
FILE f = fopen("/data/data/<application name>/<file name>", 'w');fprintf(f, "my message\n");fclose(f);
should work.
- android,NDK, write logs to a file
- Android NDK Write File
- Write a DIB to a JPEG File
- write error message to a file
- python how to write unicode to a txt file
- Write a DIB to a JPEG File (BMP2JPG)
- How to detect compilation by android ndk in a C/C++ file? cocos2dx
- Can't create/write to file '[E:/a.txt]'
- C++ - Read / Write std::map to a file
- Steps to write a simple batch bat file
- The Process of Write a File to Encryption Zone
- Android异常之 unable to write jarlist cache file
- To Write A Stack
- 从svn上下载的cocos2d-x工程报错 LOCAL_SRC_FILES points to a missing file *** Android NDK: Aborting . Stop.
- A lightweight tool to ship logs
- How to write make file?
- write to text file DEMO
- Android NDK: Your APP_BUILD_SCRIPT points to an unknown file
- 2016长乐夏令营 Day4
- easy ui 行内编辑数据并保存
- 供应链协同采购的需求分析与实现方法
- ajax提交表单问题
- today
- android,NDK, write logs to a file
- 自定义PopupWindow实现底部弹出式菜单
- mysql数据库建立外键老是失败?
- 笨方法学Python出现问题script, user_name=argv ValueError: need more than 1 value to unpack
- 顺序式video和交错式video
- 双系统时间不正确
- Python实现根据IP地址和子网掩码算出网段的方法
- java视频添加水印(logo)和视频的自动取帧
- 算法导论之贪心算法(Huffman编码和拟阵)