If your device is rooted, you can do
this:
adb root
adb shell stop
adb shell setprop log.redirect-stdio true
adb shell start
Otherwise, the next best thing is
manual logging:
Include the logging header file:
#include <android/log.h>
Use the built in logging functionality:
__android_log_print(ANDROID_LOG_INFO, "foo", "Error: %s", foobar);
By default, Android redirects stdout and stderr to /dev/null (Although Java's System.out and System.err get re-redirected to Android's logging system).