redirect stdio

950 views
Skip to first unread message

Anton Persson

unread,
Jun 12, 2010, 6:31:21 PM6/12/10
to andro...@googlegroups.com
Hi,

I've always used the following to enable logcat to display printf statements from my native code:

adb shell stop
adb shell setprop log.redirect-stdio true
adb shell start

This worked fine on any 1.6 based emulator, but the 2.2 based will never recover after that.. It halt's on the bootscreen (flashing ANDROID logo) forever...

Should I do it differently now, or use a special function besides printf, or is this a bug in 2.2?

   Best Regards 
    Anton

Onur Cinar

unread,
Jun 13, 2010, 12:42:48 AM6/13/10
to android-ndk
Hi Anton,

Instead of printf, you can use the Android log functions:

#include <android/log.h>

...

__android_log_print(ANDROID_LOG_INFO, "LogTag", "Here is my log %d",
2);

...

Then in your Android.mk file do the following:

LOCAL_LDLIBS := -llog

Regards,

-onur



---
www.zdo.com

Anton Persson

unread,
Jun 13, 2010, 12:45:09 PM6/13/10
to andro...@googlegroups.com
Hi, creating a /data/local.prop file with a line like this:

log.redirect-stdio = true

on the target solves the problem nicely. (I'd rather use printf:s if I can since that is what the code contains that I'm porting...)


Regards,

-onur



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


David Turner

unread,
Jun 13, 2010, 11:58:42 PM6/13/10
to andro...@googlegroups.com
another alternative is to start the emulator with -boot-property log.redirect.stdio=true

Anton Persson

unread,
Jun 14, 2010, 4:00:12 AM6/14/10
to andro...@googlegroups.com
David;

How come the stop; propset; start procedure doesn't work anymore, then?

   Regards  
     Anton

David Turner

unread,
Jun 14, 2010, 10:03:48 AM6/14/10
to andro...@googlegroups.com
On Mon, Jun 14, 2010 at 1:00 AM, Anton Persson <don.j...@gmail.com> wrote:
David;

How come the stop; propset; start procedure doesn't work anymore, then?


I don't know, but it nerver worked consistently in the past anyway, so tag this as "unsupported" at the moment.

Anton Persson

unread,
Jun 14, 2010, 5:36:07 PM6/14/10
to andro...@googlegroups.com
Perhaps it would be wise to update the documentation then:

http://developer.android.com/guide/developing/tools/adb.html

   Regards
     Anton

fadden

unread,
Jun 15, 2010, 1:51:04 PM6/15/10
to android-ndk
On Jun 14, 1:00 am, Anton Persson <don.juan...@gmail.com> wrote:
> How come the stop; propset; start procedure doesn't work anymore, then?

Does it work if you just stop and start without changing the property?

(You may be running up against an emulator bug that makes stop/start
fail.)

Anton Persson

unread,
Jun 17, 2010, 7:20:25 AM6/17/10
to andro...@googlegroups.com
No, even if I only do stop and start it completely hangs.


--

j

unread,
Jul 23, 2010, 11:36:43 PM7/23/10
to android-ndk
-boot-property is no a valid parameter it seems. or am i missing
something.

is below correct?

emulator -avd test_avid -prop log.redirect.stdio=true


On Jun 17, 4:20 am, Anton Persson <don.juan...@gmail.com> wrote:
> No, even if I only do stop and start it completely hangs.
>
> On Tue, Jun 15, 2010 at 7:51 PM, fadden <fad...@android.com> wrote:
> > On Jun 14, 1:00 am, Anton Persson <don.juan...@gmail.com> wrote:
> > > How come the stop; propset; start procedure doesn't work anymore, then?
>
> > Does it work if you just stop and start without changing the property?
>
> > (You may be running up against an emulator bug that makes stop/start
> > fail.)
>
> > --
> > 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%2Bunsu...@googlegroups.com>
> > .

j

unread,
Jul 23, 2010, 11:46:12 PM7/23/10
to android-ndk
I am not seeing any prinf statement in logcat even after stating
emulator with:
emulator -avd test_avid -prop log.redirect.stdio=true

printf("this is a printf statement");

Please help.

Anton Persson

unread,
Jul 24, 2010, 1:56:45 PM7/24/10
to andro...@googlegroups.com
One issue is that it will get buffered for quite some time, try doing this:

printf("this is a printf statement\n"); fflush(0);

(see the \n, and the fflush(0) call..)

To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

fadden

unread,
Jul 26, 2010, 1:55:03 PM7/26/10
to android-ndk
On Jul 24, 10:56 am, Anton Persson <don.juan...@gmail.com> wrote:
> One issue is that it will get buffered for quite some time, try doing this:
>
> printf("this is a printf statement\n"); fflush(0);
>
> (see the \n, and the fflush(0) call..)

For log.redirect-stdio, the VM is creating a thread that copies data
from fds 1 and 2 to the log file. Because each log message must be
written in its entirety, it waits until it sees an end-of-line
character before writing. Partial lines aren't going to appear in the
output, so that "\n" is very important. (See dalvik/vm/
StdioConverter.c.)

fflush(0) will flush *all* file descriptors, which is overkill.
fflush(stdout) or fflush(stderr) will suffice. You can also just mark
stdout/stderr as unbuffered with setvbuf().
Reply all
Reply to author
Forward
0 new messages