Unsolved Android and fprint(stderr,"%s",message). How?
-
Hello all!
I've got issue with custom function for logger that is exchanging standard Qt QDebug(). This function using fprint, something like this:static void __attribute__((unused)) fLoggerMessageHandler( QtMsgType inType, const QMessageLogContext& inContext, const QString& inMessage ) { ... fprintf(stderr,"[INF] %s \n",inMessage.toStdString().c_str()); ... }
and registering it in main.cpp:
qInstallMessageHandler(fLoggerMessageHandler);
It's working everywhere but not on Android. Why? What am I missing?
-
@bogong
Please excuse if I am quite wrong, because I don't use Android, but where are you expectingstderr
to go to under Android? My briefest search giave me:By default, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null.
-
@JonB I know it. I am trying to make it works. I need to print logs like qDebug.
-
All that I found for now this:
- https://groups.google.com/g/android-ndk/c/fGjiXk1rohs?pli=1
- https://manski.net/2012/05/logging-from-c-on-android/
- https://www.programmersought.com/article/78256728726/
But I don't know where to find this header
#include <android/log.h>
-
@bogong You could forward the output to a logfile. See https://stackoverflow.com/questions/14543443/in-c-how-do-you-redirect-stdin-stdout-stderr-to-files-when-making-an-execvp-or
-
@jsulm Thx I am already writing it into db. I need exactly to write it in console. For now I've found two ways:
- to use <android/log.h>, but I don't know where to find library itself (header file located in $ANDROID_SDK_ROOT/sysroot/usr/include)
- to use Log Cat, but it will require me to write Java native component
When I get free time, will look on how it developed in QT Sources.
If anyone knows the solution - write it here please.