Pages

Get it free, Try now

Free Cell Phones

Monday, October 4, 2010

how to use Logs in Android Application and Android NDK

We will first see how to use logs on Android Application side and then we look into usage of logs on Native side(NDK)

On Application side
Import log provided by Android
import android.util.Log;

then use below two lines of code where ever needed
String TAG ="ModuleName";
Log.d(TAG,"File Name is =%s"+ testFilename );

Use following based on the priority constants

Priority Usage

DEBUG Log.d
ERROR Log.e
INFO Log.i
VERBOSE Log.v
WARN Log.w
WTF Log.wtf

WTF(What a Terrible Failure): Report an exception that should never happen.

Inside Native code
Similarly in Native code include the header and call the ' __android_log_print' , '__android_log_write' with appropriate priority constants, do not miss to the library in the Android.mk fail to which leads to linker issues.

Add below line in Android.mk
......
LOCAL_LDLIBS := -llog
....

Include header
...
#include "android/log.h"
....
then call
{..
__android_log_print(ANDROID_LOG_INFO, "ModuleName FunctionName", "Enter");
...
...
__android_log_print(ANDROID_LOG_INFO, "ModuleName FunctionName", "Exit");
}


or
{
__android_log_write(ANDROID_LOG_ERROR, "ModuleName FunctionName", "#1");
....
}

use below priority constants or find directly under 'C:\android-ndk-r4b\build\platforms\android-8\arch-arm\usr\include\android'
ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT,

No comments:

Post a Comment