Putting Log in Native Code

Hi All,

This post is to put logs in the Native code  which will show in DDMS.

Following is the detail for log function for native code.

Lib Name:- liblog.so

HeaderFile:-    “android/log.h”

Function:-  int   __android_log_write(int prio, const char *tag, const char *text);

For Log Priority you can use following Value.

    ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
Tag :- It is up to you which tag you want to use for filtering in DDMS.
Text:- A simple text which you use in printf format.
Now a very small example  how we can you this Log function
1) First make some changes in Android.mk file so that you can link to liblog.so.
2) After this I just include the header file as
#include <android/log.h>

3) Define Macros as

#define  LOG_TAG    "YS" #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
All is done now you can use the LOGI() macro for putting logs.
This entry was posted in Debugging Native Libary. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s