Log logs in Android JNI

Source: Internet
Author: User

There are interfaces in Android JNI that provide the relevant interface to log logs, so that, like Java-written code, can be viewed directly in Logcat. If the code is the log API provided by Android, once you encounter new requirements, it will be cumbersome to change, every place needs to be modified, so it is necessary to encapsulate the log API provided by Android.

Common APIs provided by Android

__android_log_write (Android_log_info, "tag here", "message Here"), __android_log_print (Android_log_info, "Sometag", " Test int =%d ", testint);


How do I use it?

1. Include Header files

#include <android/log.h>

2. Link the relevant library files

Android.mk need to add the introduction library

Local_ldlibs + =-l$ (sysroot)/usr/lib-llog

Packaging

#include <stdio.h> #include <stdarg.h> #include <android/log.h> #include <time.h>static const char* TAG = "Uninstall"; void kesyprintf (const char *format, ...)       {#ifdef Ke_debug char buf[2048] = "n";    Va_list args;    Va_start (Args,format);    vsprintf (buf + strlen (buf), format, args);         Va_end (args);   Can add the function, here can log in the file//-----__android_log_write (Android_log_info, TAG, buf); #endif}

. Ke_debug is a macro definition, and as a switch, only the ke_debug is defined to output log. It can be defined in code or in the Mk file.

. So you can print the log like printf in C.

Kesyprint ("Hello world\n");

Kesyprint ("ABC---%s", "EFG");



Log logs in 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.