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. [SOLVED] Qt wrapper around syslog
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Qt wrapper around syslog

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 8.5k Views 1 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.
  • clogwogC Offline
    clogwogC Offline
    clogwog
    wrote on last edited by
    #1

    does qt have a class that allows writing to the linux syslog ?
    (and presumably does something different on a different os )

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      No, you'll have to do that with platform-dependent methods yourself
      (https://www.gnu.org/software/libc/manual/html_node/Submitting-Syslog-Messages.html )

      1 Reply Last reply
      0
      • clogwogC Offline
        clogwogC Offline
        clogwog
        wrote on last edited by
        #3

        thank you DerManu !
        i couldn't find it anywhere, now i know why.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          KDTools from KDAB provides a logging facility that can use syslog (or other means on other platform)

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • clogwogC Offline
            clogwogC Offline
            clogwog
            wrote on last edited by
            #5

            thanks SGaist ! i'll have a look at that now.

            in the mean time: it's not pretty but here's my wrapper (linux only)

            @#ifndef QSYSLOG_H
            #define QSYSLOG_H

            #include <QObject>
            #include <syslog.h>

            class QSyslog : public QObject
            {
            Q_OBJECT
            public:
            static void setAppName(QString appName) { QSyslog::appName = appName; }
            static QSyslog& instance(); // singleton accessor
            static void free(); // singleton free

            static void Syslog(int level, QString message);
            

            private:
            QSyslog();

            static QSyslog* singleton;
            static QString appName;
            

            };
            #endif // QSYSLOG_H
            @

            @#include "qsyslog.h"

            #include <QTime>
            #include <QDebug>

            QSyslog* QSyslog::singleton = NULL;
            QString QSyslog::appName = "call_setAppName_before_using";

            QSyslog::QSyslog() :
            QObject(NULL)
            {
            }

            QSyslog& QSyslog::instance()
            {
            if( NULL == singleton )
            {
            singleton = new QSyslog();
            void openlog(const char *ident, int option, int facility);
            }
            return *singleton;
            }
            void QSyslog::free()
            {
            if( NULL != singleton )
            {
            delete singleton;
            singleton = NULL;
            closelog();
            }
            }

            void QSyslog::Syslog(int level, QString message)
            {
            QTime rightNow = QTime::currentTime();
            qDebug() << rightNow.toString() + " " + QString::number(level) + " " + message;
            syslog(level, (const char *)message.toLatin1());
            }
            @

            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