Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. howto: redirect console output to syslog
Forum Updated to NodeBB v4.3 + New Features

howto: redirect console output to syslog

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.8k 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.
  • A Offline
    A Offline
    alpartis
    wrote on 15 Nov 2021, 14:55 last edited by
    #1

    I have a QtQuick/QML application running on a remote embedded target system. I have syslog configured on the target to direct log messages to a log server.

    Now, I'd like to have the standard out and err console output also redirected to the local syslog so I can get all of my application feedback in one place.

    Is there a "best practices" way to do this? Or will I want/need to obtain all this output within my application and log it through "normal channels"?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alpartis
      wrote on 21 Nov 2021, 22:27 last edited by
      #6

      The solution that works for me (your mileage may vary) is to call qInstallMessageHandler() from the Qt Core package and supply my own QtMessageHandler function. There's a nice example of this in the help docs.

      https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 15 Nov 2021, 17:46 last edited by
        #2

        @alpartis said in howto: redirect console output to syslog:

        Is there a "best practices" way to do this?

        Don't print debug and error message to stdout/stderr but use a proper logging system. Printing somthing to stdout/err is for sure nothing to be considered except basic debugging or a command line program.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply 16 Nov 2021, 19:50
        0
        • J Offline
          J Offline
          JoeCFD
          wrote on 15 Nov 2021, 17:57 last edited by JoeCFD
          #3

          Also it may not be a good idea to send the standard out and err console output of your app to syslog because it can be a lot. And you may not want to mess up with OS output. It may be better to send them to a file. You can use Qt logging system to replace std output.
          https://doc.qt.io/qt-5/qloggingcategory.html

          A 1 Reply Last reply 16 Nov 2021, 19:55
          0
          • C Christian Ehrlicher
            15 Nov 2021, 17:46

            @alpartis said in howto: redirect console output to syslog:

            Is there a "best practices" way to do this?

            Don't print debug and error message to stdout/stderr but use a proper logging system. Printing somthing to stdout/err is for sure nothing to be considered except basic debugging or a command line program.

            A Offline
            A Offline
            alpartis
            wrote on 16 Nov 2021, 19:50 last edited by
            #4

            @Christian-Ehrlicher I am mostly concerned with messages that Qt prints to stderr. In my target execution environment, the console output is lost, so it would be helpful to get the various warnings and errors that the Qt library code generates (especially with regard to QML errors that are not encountered until runtime) redirected to the system logger.

            I'm aware that I can do this by redirecting stdout and stderr when my application is launched. My question is whether there is a better way to do this from within the application itself.

            1 Reply Last reply
            1
            • J JoeCFD
              15 Nov 2021, 17:57

              Also it may not be a good idea to send the standard out and err console output of your app to syslog because it can be a lot. And you may not want to mess up with OS output. It may be better to send them to a file. You can use Qt logging system to replace std output.
              https://doc.qt.io/qt-5/qloggingcategory.html

              A Offline
              A Offline
              alpartis
              wrote on 16 Nov 2021, 19:55 last edited by
              #5

              @JoeCFD: Whether, or not, it's a good idea, there is very helpful information that the Qt library code prints to the console (stderr for the most part) and in my case, that information will be lost if it isn't redirected to a persistent destination. It's not a matter of my use of a Qt logging API, but the Qt library's use of such things. When the Qt library points out that it's not displaying one of my QML components because it cannot find one of my sub-components, it does so through stderr -- I just want to know the best way to get that information to the logger where I can see and record it.

              1 Reply Last reply
              1
              • A Offline
                A Offline
                alpartis
                wrote on 21 Nov 2021, 22:27 last edited by
                #6

                The solution that works for me (your mileage may vary) is to call qInstallMessageHandler() from the Qt Core package and supply my own QtMessageHandler function. There's a nice example of this in the help docs.

                https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

                1 Reply Last reply
                1

                1/6

                15 Nov 2021, 14:55

                • Login

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