The native code in JNI prints the logs into Eclipse's Logcat

Source: Internet
Author: User

1 Add NDK to log support
If you need to add the NDK support for log, only the following 2 steps can be implemented.


1.1 Modifying Android.mk
If the resulting library file is a ". So file", add the following in Android.mk:
local_ldlibs:=-l$ (sysroot)/usr/lib-llog
If the generated library file is ". A file", add the following in Android.mk:
Local_ldlibs:=-llog

1.2 Referencing a log header file in a. C or. cpp file
Add the following content:
Introduction of Log header file
#include <android/log.h>
Log label
#define TAG "Fill in the log tag here"
Defining Info Info
#define Logi (...) __android_log_print (android_log_info,tag,__va_args__)
Defining debug information
#define LOGD (...) __android_log_print (Android_log_debug, TAG, __va_args__)
Define error information
#define LOGE (...) __android_log_print (android_log_error,tag,__va_args__)

Android_log_info: is the log level;
Tag: is the label to be filtered and can be filtered in the Logcat view.
__va_args__: is the actual log content.
After completing the 2 steps above, we can add Logi, LOGD, loge to print the information in the. c/cpp file! Using Logi, LOGD, Loge and the same way you use printf

1.3 Log types
1) log.v debugging color is black, any message will be output, here V for verbose wordy meaning, usually used is log.v (,);
2) The output color of LOG.D is blue, only the meaning of debug debugging is output, but he will output the upper level of information, filtering can be selected by DDMS logcat tag
3) LOG.I output is green, general informational message information, it will not output LOG.V and LOG.D information, but will display I, W and e information
4) LOG.W meaning orange, can be seen as a warning warning, generally need us to pay attention to optimize the Android code, while selecting it will also output LOG.E information.
5) LOG.E is red, can think of error errors, here only the red error message, these errors need our careful analysis, view the stack of information.

Such as:

Logi ("User info----name:%s, age:%d, sex:%s.", "xxx", 18, "male");

Execute the previous sentence code to print out the corresponding log in Logcat.

Note: The log printing method cannot pass in jstring, the jstring must be converted to a character array in C to print in the method, or it will be an error.

The native code in JNI prints the logs into Eclipse's Logcat

Related Article

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.