From cc9f00624c00ce5e40bb258e1f315732714a1de3 Mon Sep 17 00:00:00 2001 From: Enrico Tagliavini Date: Sat, 19 Jun 2010 13:12:50 +0200 Subject: [PATCH] Adding support for syslog --- src/common/logger.cpp | 20 ++++++++++++++++++++ src/common/main.cpp | 3 +++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 17c473b..88d5f3d 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -25,6 +25,11 @@ #include #include +#ifndef Q_OS_WIN32 +#include +#include +#endif /* Q_OS_WIN32 */ + Logger::~Logger() { QDateTime date = QDateTime::currentDateTime(); if(_logLevel == DebugLevel) _buffer.prepend("Debug: "); @@ -44,6 +49,21 @@ void Logger::log() { else lvl = InfoLevel; if(_logLevel < lvl) return; + + #ifndef Q_OS_WIN32 + static bool slog = Quassel::isOptionSet("syslog"); + if(slog) { + int prio; + switch (lvl) { + case DebugLevel: prio = LOG_DEBUG; break; + case InfoLevel: prio = LOG_INFO; break; + case WarningLevel: prio = LOG_WARNING; break; + case ErrorLevel: prio = LOG_ERR; break; + default: prio = LOG_INFO; break; + } + syslog(LOG_USER & prio, "%s", qPrintable(_buffer)); + } + #endif /* Q_OS_WIN32 */ // if we can't open logfile we log to stdout QTextStream out(stdout); diff --git a/src/common/main.cpp b/src/common/main.cpp index d0e0840..edcb45e 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -110,6 +110,9 @@ int main(int argc, char **argv) { cliParser->addSwitch("add-user", 0, "Starts an interactive session to add a new core user"); cliParser->addOption("change-userpass ", 0, "Starts an interactive session to change the password of the user identified by username"); #endif +#ifndef Q_OS_WIN32 + cliParser->addSwitch("syslog", 0, "Send the log to syslog. If used with --logfile the log will be stored in both"); +#endif /* Q_OS_WIN32 */ #ifdef HAVE_KDE // the KDE version needs this extra call to parse argc/argv before app is instantiated -- 1.7.1