Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android and fprint(stderr,"%s",message). How?
Forum Updated to NodeBB v4.3 + New Features

Android and fprint(stderr,"%s",message). How?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • B Offline
      B Offline
      bogong
      wrote on last edited by bogong
      #7

      Finally found solution :-)))) Just been reading carefully manuals :-))))
      Here published example for this issue

      1 Reply Last reply
      0
      • B bogong

        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?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #2

        @bogong
        Please excuse if I am quite wrong, because I don't use Android, but where are you expecting stderr 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.

        B 1 Reply Last reply
        0
        • JonBJ JonB

          @bogong
          Please excuse if I am quite wrong, because I don't use Android, but where are you expecting stderr 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.

          B Offline
          B Offline
          bogong
          wrote on last edited by
          #3

          @JonB I know it. I am trying to make it works. I need to print logs like qDebug.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bogong
            wrote on last edited by bogong
            #4

            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>
            
            jsulmJ 1 Reply Last reply
            0
            • B bogong

              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>
              
              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              B 1 Reply Last reply
              0
              • jsulmJ jsulm

                @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

                B Offline
                B Offline
                bogong
                wrote on last edited by bogong
                #6

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

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bogong
                  wrote on last edited by bogong
                  #7

                  Finally found solution :-)))) Just been reading carefully manuals :-))))
                  Here published example for this issue

                  1 Reply Last reply
                  0
                  • B bogong has marked this topic as solved on

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved