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. How to print to syslog on macOS?
Forum Updated to NodeBB v4.3 + New Features

How to print to syslog on macOS?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.8k Views 2 Watching
  • 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.
  • V Offline
    V Offline
    Vadi2
    wrote on last edited by
    #1

    I'd like to print to print to the Console.app on macOS, and qDebug() doesn't seem to do the job for me. This answer suggests using the logger or the syslog commands, which work from the terminal but not when I call them from within my app:

    QProcess().start("/usr/bin/logger", QStringList() << "0 launched from update?");
    QProcess().start("syslog", QStringList() << "-s -l notice This message should show up in with a Facility of syslog.");
    

    Any ideas on what's going wrong?

    kshegunovK 1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Maybe something like that:

      #ifdef Q_OS_MAC
      #include <syslog.h>
       static void SYSLOG(const char* format,...)
             {
              va_list vaList;
              va_start( vaList,format );
              vsyslog(LOG_ERR,format,vaList);
             }
        #endif
      
      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vadi2
        wrote on last edited by
        #3

        It doesn't error, runs fine, but nothing appears. This is puzzling.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

          0_1509808833885_Console.png

          1 Reply Last reply
          0
          • V Vadi2

            I'd like to print to print to the Console.app on macOS, and qDebug() doesn't seem to do the job for me. This answer suggests using the logger or the syslog commands, which work from the terminal but not when I call them from within my app:

            QProcess().start("/usr/bin/logger", QStringList() << "0 launched from update?");
            QProcess().start("syslog", QStringList() << "-s -l notice This message should show up in with a Facility of syslog.");
            

            Any ideas on what's going wrong?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            Besides what @mpergand wrote, your calls seem wrong.

            QProcess syslog;
            // Connect signals to your slots to listen to errors and such here! Don't just blindly hope you'd hit something right.
            // ...
            // Pass the arguments to the process correctly. Think how is the `QProcess` class to escape them if you pass only 1 large string, and how is `syslog` to know which spaces are significant which are not ...?
            syslog.start("syslog", QStringList() << "-s" << "-l" << "notice" << "This message should show up in with a Facility of syslog.");
            
            

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vadi2
              wrote on last edited by
              #6

              I forgot the part where I need to call waitForFinished() as well. SYSLOG() worked at some point too, but I'll go with the process variant since I can pipe things into it. Big thanks to both of you!

              1 Reply Last reply
              0

              • Login

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