How to display logs from .CPP file in LogCat?

10,973 views
Skip to first unread message

Atul Prakash

unread,
Apr 20, 2011, 3:37:18 AM4/20/11
to android-ndk
Hello Friends,

I am using .CPP file in my Android Project using NDK. Is there any
function through which I can display any output from my .CPP file just
like System.out.println("Message"); or Log.d("Message"); in .java
files which is being displayed in LogCat as output message.

This technique of displaying output on LogCat will help me check the
program flow.

Is cout<<"Message" or printf("Message"); of C/C++ will work on .CPP
files which I am implementing through NDK? If yes then where can I get
these output messages i.e. either on LogCat or on Cygwin console or
somewhere else.

I have also tried to use:

#include <android/log.h>

In some method I have also written this, in order to print it in
LogCat, but I got no output.

__android_log_print(ANDROID_LOG_INFO, "This is my first log in
LogCat");
__android_log_print(ANDROID_LOG_INFO, "Tank", "resize w=%d h=%d", w,
h);

I have also added following line to Android.mk file:

LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog

Please tell me what is missing in my .CPP code in order to display
Logs on LogCat.

Thanks in advance.

Atul Prakash Singh

liuwg2005

unread,
Apr 20, 2011, 3:54:33 AM4/20/11
to android-ndk
try to change 'ANDROID_LOG_INFO' to 'ANDROID_LOG_DEBUG'
 
 
2011-04-20

liuwg2005

发件人: Atul Prakash
发送时间: 2011-04-20  15:37:26
收件人: android-ndk
抄送:
主题: How to display logs from .CPP file in LogCat?
-- 
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Atul Prakash

unread,
Apr 20, 2011, 4:09:38 AM4/20/11
to android-ndk
Changing ANDROID_LOG_INFO to ANDROID_LOG_DEBUG didn't work.

I would also like to know about the number & type of arguments
__android_log_print() method takes as I am getting
error : too few arguments to function int __android_log_print(int ,
const *char, const *char, .. );

Riasat Abir

unread,
Apr 20, 2011, 4:11:45 AM4/20/11
to andro...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--

HimHim

mic _

unread,
Apr 20, 2011, 4:42:11 AM4/20/11
to andro...@googlegroups.com
>>I would also like to know about the number & type of arguments __android_log_print() method takes

int __android_log_print(int prio, const char *tag, const char *fmt, ...)

/Michael

Atul Prakash

unread,
Apr 20, 2011, 5:00:18 AM4/20/11
to android-ndk
Thanks everybody!!!! It worked.

On Apr 20, 1:42 pm, mic _ <micol...@gmail.com> wrote:
> >>I would also like to know about the number & type of arguments
>
> __android_log_print() method takes
>
> int __android_log_print(int prio, const char *tag, const char *fmt, ...)
>
> /Michael
>
>
>
>
>
>
>
> On Wed, Apr 20, 2011 at 10:11 AM, Riasat Abir <riasat.a...@gmail.com> wrote:
> > This worked for me:
> >http://stackoverflow.com/questions/5459324/how-to-see-printf-lines-in...
>
> > On Wed, Apr 20, 2011 at 2:09 PM, Atul Prakash <atul.prakas...@gmail.com>wrote:
>
> >> Changing ANDROID_LOG_INFO to ANDROID_LOG_DEBUG didn't work.
>
> >> I would also like to know about the number & type of arguments
> >> __android_log_print() method takes as I am getting
> >> error : too few arguments to function int __android_log_print(int ,
> >> const *char, const *char, .. );
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "android-ndk" group.
> >> To post to this group, send email to andro...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> android-ndk...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-ndk?hl=en.
>
> > --
>

Cherwoo Kim

unread,
Apr 20, 2011, 5:50:00 AM4/20/11
to android-ndk
Hi, Atul.

Printing log to Logcat is quite easy.

Try to include the head file <utils/Log.h>, and use LOGE, LOGW, LOGD,
LOGI, LOGV functions to print Error, warning, debug, info, verbose
messages to logcat.

For example:

#define LOG_TAG XXX // its the tag u can see in the logcat.
#include <utils/Log.h>

...
...

LOGE("mmmmmm printing log %s,%d",__FILE__,__LINE__);// it's gonna be
printed in error level, with tag XXX

You can find similar use of LOG utils in android cpp source files.

Hope this helps.
Reply all
Reply to author
Forward
0 new messages