[SOLVED] Qt wrapper around syslog
-
does qt have a class that allows writing to the linux syslog ?
(and presumably does something different on a different os ) -
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 ) -
thank you DerManu !
i couldn't find it anywhere, now i know why. -
Hi,
KDTools from KDAB provides a logging facility that can use syslog (or other means on other platform)
Hope it helps
-
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 freestatic 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());
}
@