__android_log_print

3,885 views
Skip to first unread message

Ajay

unread,
Aug 11, 2010, 5:00:41 AM8/11/10
to android-ndk
Hi,
I am using __android_log_print and able to print the log messages
on logcat. The issue is that if I use any access specifiers like %d,
%s, etc, I can see only garbage characters at those places. If I log a
simple message without any %d or %s, the message is logged correctly.
Does anyone have an idea about this issue?

Thanks,
AJ

Onur Cinar

unread,
Aug 12, 2010, 12:46:29 PM8/12/10
to andro...@googlegroups.com

Hi Ajay,

I'm using the logging functions without any problems. Could you post a sample code to demonstrate the issue?

Regards,

-onur


--
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.

---
www.zdo.com

charles

unread,
Aug 13, 2010, 5:19:43 AM8/13/10
to android-ndk
Hi,

Here is some example code for writing to the Android log in a printf-
like manner. I pulled this function from some code I use in a native
app that is written to write to both Linux syslog and Android log, so
it is a bit weird. I tried to clean it up a bit though. The full
source is here:

The trick is to satisfy the function prototype for
__android_log_vprint() function defined in the /usr/include/android/
log.h header file. The function you are trying to use does not (IIRC)
handle formatted strings -- so there is your problem!

Here is an example function for writing to the Android log a formatted
string:

void android_syslog(int level, const char *format, ...)
{
va_list arglist;

va_start(arglist, format);
__android_log_vprint(level, "my_app", format, arglist);
va_end(arglist);

return;
}

And here is an example call to this function:

android_syslog(ANDROID_LOG_INFO, "pid is", getpid());

Which should print something like this to the Android syslog:
I/my_app (9390 ): pid is 9380

For a full example, take a look here: http://wlan-lj.net/browser/trunk/meshapp/guilib/src/log.c

(Note in this example, writing to both GNU/Linux syslog and Android
syslog is provided).

Hope this helps. Good luck! :)

- Charles

On Aug 12, 11:46 am, Onur Cinar <onur.ci...@gmail.com> wrote:
> Hi Ajay,
>
> I'm using the logging functions without any problems. Could you post a
> sample code to demonstrate the issue?
>
> Regards,
>
> -onur
>
>
>
>
>
> On Wed, Aug 11, 2010 at 2:00 AM, Ajay <aja...@gmail.com> wrote:
> > Hi,
> >   I am using __android_log_print and able to print the log messages
> > on  logcat. The issue is that if I use any access specifiers like %d,
> > %s, etc, I can see only garbage characters at those places. If I log a
> > simple message without any %d or %s, the message is logged correctly.
> >  Does anyone have an idea about this issue?
>
> > Thanks,
> > AJ
>
> > --
> > 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<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

charles

unread,
Aug 13, 2010, 6:35:26 AM8/13/10
to android-ndk
Oops! The example call to the function contains an error, it should
be:

android_syslog(ANDROID_LOG_INFO, "pid is %d", getpid());

That '%d' is important!
Reply all
Reply to author
Forward
0 new messages