본문 바로가기

Android

ndk log

 

http://blog.blackwhale.at/2009/08/android-ndk-logging/

 

So after the first few mini steps into the NDK the first thing you will probably notice missing, is a way to retrieve log messages through logcat. To be able to do this you need to do two things:

 

1. Include log.h in your source files

#include 

2. Be sure to add llog to your LOCAL_LDLIBS in the Android.mk file of your NDK code

LOCAL_LDLIBS := -llog

Now you are ready to log to logcat from you NDK code, simply via

__android_log_write(ANDROID_LOG_ERROR,"Tag","Message");

Further loglevels are

typedef enum android_LogPriority {
    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,     /* only for SetMinPriority(); must be last */
} android_LogPriority;

all the other stuff you can look up under