How to play Log in C + + of Android JNI

Source: Internet
Author: User
Tags define definition

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.