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