Logging stdio

329 views
Skip to first unread message

Phil Endecott

unread,
Oct 31, 2010, 5:00:21 PM10/31/10
to android-ndk
Last discussed here:

http://groups.google.com/group/android-ndk/browse_thread/thread/b5e6f77db61cd974

Apparently, although the docs at http://developer.android.com/guide/developing/tools/adb.html#logcat
(see "Viewing stdout and stderr") says:

"By default, the Android system sends stdout and stderr
(System.out and System.err) output
to /dev/null. In processes that run the Dalvik VM, you can have
the system write a copy of the
output to the log file

this doesn't work for stdout and stderr from native code, but only
from the Java System.out and System.err streams. So:

- Is this supposed to work, but I'm doing something wrong?
- Or is this a bug in the docs?
- Or is someone going to suggest that "stdout and stderr" in that
quote doesn't mean what I think it does, and it's my fault for not
understanding?

Also: is there some other way that I can achieve this?

Thanks, Phil.

alan

unread,
Nov 1, 2010, 10:47:50 AM11/1/10
to android-ndk
dont use std out and std error, use a proper logging system which
writes using the android logging functions

On Oct 31, 9:00 pm, Phil Endecott <spam_from_goo...@chezphil.org>
wrote:
> Last discussed here:
>
>    http://groups.google.com/group/android-ndk/browse_thread/thread/b5e6f...
>
> Apparently, although the docs athttp://developer.android.com/guide/developing/tools/adb.html#logcat

Phil Endecott

unread,
Nov 1, 2010, 11:44:27 AM11/1/10
to android-ndk
> dont use std out and std error, use a proper logging system which
> writes using the android logging functions

Please suggest something that's portable to all the platforms on which
I want to run this code.

(Can I take it that "you can have the system write a copy of [stdout
and stderr] to the log file" is a documentation bug then?)

Tim Mensch

unread,
Nov 1, 2010, 12:31:15 PM11/1/10
to andro...@googlegroups.com
On 11/1/2010 9:44 AM, Phil Endecott wrote:

>> dont use std out and std error, use a proper logging system which
>> writes using the android logging functions
>
> Please suggest something that's portable to all the platforms on
> which I want to run this code.


Everything is portable with an intermediate interface. From a macro that
turns your logging function into a platform-specific one to a function
with platform-specific implementations, the options are many.

See http://en.wikipedia.org/wiki/Bridge_pattern, though the
implementation in this case can be pretty trivial (a single function
that you expose to your code that has multiple implementations).

Tim

Phil Endecott

unread,
Nov 1, 2010, 5:22:08 PM11/1/10
to android-ndk
> Everything is portable with an intermediate interface.

Sure, that's what I have. But Alan's reply seemed to suggest that
there already exists a "proper" logging library that provides this.
I'm not aware of such a thing.

Anyway, are we agreed that this is a bug in the docs? Is
http://code.google.com/p/android/issues the right place for that, or
is the documentation managed separately?

Chris Stratton

unread,
Nov 2, 2010, 12:13:18 AM11/2/10
to android-ndk
On Oct 31, 5:00 pm, Phil Endecott <spam_from_goo...@chezphil.org>
wrote:

>     "By default, the Android system sends stdout and stderr
> (System.out and System.err) output

It looks like you could use freopen() to reassign stdout to an actual
file on the sdcard, or perhaps a named pipe

Or with a little research on streams in C you should be able to figure
out how to grab it and stuff the results into the native front end to
logcat. You might even be able to do it from java.

Sman

unread,
Nov 2, 2010, 8:04:34 AM11/2/10
to android-ndk
You are right.
I'm using reopen for stderr. Ex:
FILE* f = freopen( "/sdcard/stderrout.txt", "w", stderr );
It is easiest way.
And your app should have write files permission.
Reply all
Reply to author
Forward
0 new messages