http://blog.csdn.net/pkigavin/article/details/8583537
Recently, in the study of the Android 2.3.3 Source code c/S layer, you need to do some debugging of the code, but strangely, directly add logd ("XXXXXXXX"), use logcat but do not see any output, switch to Logi, LOGV, LOGW, Loge also has no effect. So on the Internet to find solutions, after several trials, finally found, and now posted to the following memo:
First step: add: local_ldlibs: =-llog in the corresponding MK file
Step two: In the CPP file to use log, add:
#include <android/log.h>
#define LOGD (...) __android_log_print (Android_log_debug, "Keymatch", __va_args__)
The third step: This can be used: logd ("I want to see the debug information ^_^"); In this way, the output seen on the Logcat side is: D/keymatch (32): I want to see the debug information ^_^ if you want to change the output of the various content, you can refer to the corresponding color, for example, if you want to define Loge, you can put the above Android_log_ Debug to Android_log_error, in the same vein, logi god Horse and so on:
#define LOGV (...) __android_log_print (Android_log_verbose, "ProjectName", __va_args__)
#define LOGD (...) __android_log_print (Android_log_debug, "ProjectName", __va_args__)
#define Logi (...) __android_log_print (Android_log_info, "ProjectName", __va_args__)
#define LOGW (...) __android_log_print (Android_log_warn, "ProjectName", __va_args__)
#define LOGE (...) __android_log_print (Android_log_error, "ProjectName", __va_args__)
Of course, if not too troublesome, you can also directly use the __android_log_print function, and not define definition logxxx if you want to know more details, you can also refer to this article: "On Android output log information for debugging" in addition, It is said that this method may cause problems when compiling the dynamic library, which will prompt cannot find-llog error. It means that I can't find liblog.so this library file. therefore need to change to local_ldlibs:=-l$ (sysroot)/usr/lib-llog only then can compile normally. But when I compile the dynamic library, as if not to change the line, did not find the compile-time prompt "Cannot find-llog" error.
How to play Log in C + + of Android JNI