Important: Please read the Qt Code of Conduct -

How to print to syslog on macOS?

  • I'd like to print to print to the 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?

  • Maybe something like that:

    #ifdef Q_OS_MAC
    #include <syslog.h>
     static void SYSLOG(const char* format,...)
            va_list vaList;
            va_start( vaList,format );

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

  • 0_1509808833885_Console.png

  • Qt Champions 2017

    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.");

  • 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!

Log in to reply