Logging

5,620 views
Skip to first unread message

Chander Pechetty

unread,
Jul 1, 2009, 10:01:22 AM7/1/09
to android-ndk
Whats the correct way to log messages for debugging native code? I
have tried the following options, and #3 works.

Option 1:
I tried linking with liblog like so in Android.mk:
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
and
1. included log.h - which failed
2. included android/log.h - this passes, but get an
"undefined reference to `LOGE'


Option 2:
I tried the regular printf, fprintf to stdout - which doesnot output
anything to logcat

Option 3:
fprintf to file obviously works.

How to fix option 1 and 2 ?


Thanks
Chander

Chander Pechetty

unread,
Jul 1, 2009, 10:01:47 AM7/1/09
to android-ndk
Whats the correct way to log messages for debugging native code? I
have tried the following options, and #3 works.

Option 1:
I tried linking with liblog like so in Android.mk:
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
and
1. included log.h - which failed
2. included android/log.h - this passes, but get an
"undefined reference to `LOGE'


Option 2:
I tried the regular printf, fprintf to stdout - which does not output

David Turner

unread,
Jul 1, 2009, 11:13:48 AM7/1/09
to andro...@googlegroups.com
<android/log.h> doesn't define LOGE, LOGD, etc.. but only a few functions like __android_log_print() that you are free to wrap around your own logging/debugging macros.
I invite you to have a look at its content (build/platforms/android-1.5/common/include/android/log.h), since there are many useful comments here.

LOGD/LOGE are used internally by the Android sources (in <cutils/log.h>), but are not exposed by the NDK for fear of conflict with other logging systems.

Eurico Inocêncio

unread,
Jul 1, 2009, 11:14:22 AM7/1/09
to andro...@googlegroups.com
Hello

With option 1 you just need to define your own helper macros, this is
what I did in my own debug header

#include <android/log.h>

#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "libnav",
__VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , "libnav",
__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO , "libnav",
__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN , "libnav",
__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR , "libnav",
__VA_ARGS__)

#endif // ANDROID_ALOG_H

Works very well

Eurico

2009/7/1 Chander Pechetty <cspec...@gmail.com>:

Chander Pechetty

unread,
Jul 1, 2009, 12:34:39 PM7/1/09
to android-ndk
David and Eurico,
Thanks a bunch for the tip. It works !!!
I did a search for LOGD earlier, but there were too many references
in several places in android source, and I just switched to fprintfs.
Whats the easiest way to look at
"build/platforms/android-1.5/common/include/android/log.h" without
using GIT-WEB.
I have cupcake checkout using repo, but I don't find a link to the
above file.

Thanks
Chander

On Jul 1, 8:14 pm, Eurico Inocêncio <eurico.inocen...@gmail.com>
wrote:
> Hello
>
> With option 1 you just need to define your own helper macros, this is
> what I did in my own debug header
>
> #include <android/log.h>
>
> #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "libnav",
> __VA_ARGS__)
> #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG  , "libnav",
> __VA_ARGS__)
> #define LOGI(...) __android_log_print(ANDROID_LOG_INFO   , "libnav",
> __VA_ARGS__)
> #define LOGW(...) __android_log_print(ANDROID_LOG_WARN   , "libnav",
> __VA_ARGS__)
> #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR  , "libnav",
> __VA_ARGS__)
>
> #endif // ANDROID_ALOG_H
>
> Works very well
>
> Eurico
>
> 2009/7/1 Chander Pechetty <cspeche...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages