# -DWITH_KDE=ON : Enable KDE4 support
# -DWITH_CRYPT=OFF : Disable encryption support
# -DWITH_OXYGEN=(ON|OFF) : Whether to install Oxygen icons (default: yes, unless KDE > 4.3.0 is present and enabled)
+# -DWITH_SYSLOG=OFF : Use syslog for logging
#
# -DEMBED_DATA=ON : Embed all data files in icons the binary, rather than installing them separately
#
option(WITH_LIBINDICATE "Enable Ayatana notification support" ON)
option(WITH_KDE "Enable KDE4 integration" OFF)
option(WITH_CRYPT "Enable encryption support if present on system" ON)
+option(WITH_SYSLOG "Use syslog for storing log data" OFF)
# We use icon paths from KDE 4.3.x, which are partially invalid on older and possibly
# even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
option(DEPLOY "Mac OS X only! Adds required libs to bundle resources and create a dmg. Note: requires Qt to be built with 10.4u SDK" OFF)
endif(APPLE)
+if(WITH_SYSLOG)
+ check_include_file(syslog.h HAVE_SYSLOG_H)
+endif(WITH_SYSLOG)
+
# Default to embedding data in the static case
if(STATIC OR WIN32)
set(EMBED_DEFAULT ON)
#include "logger.h"
#include "quassel.h"
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#else
#include <QFile>
#include <QTextStream>
#include <QDateTime>
+#endif
Logger::~Logger() {
QDateTime date = QDateTime::currentDateTime();
- if(_logLevel == DebugLevel) _buffer.prepend("Debug: ");
- else if (_logLevel == InfoLevel) _buffer.prepend("Info: ");
- else if (_logLevel == WarningLevel) _buffer.prepend("Warning: ");
- else if (_logLevel == ErrorLevel) _buffer.prepend("Error: ");
+
+ switch (_logLevel) {
+ case DebugLevel:
+ _buffer.prepend("Debug: ");
+ break;
+ case InfoLevel:
+ _buffer.prepend("Info: ");
+ break;
+ case WarningLevel:
+ _buffer.prepend("Warning: ");
+ break;
+ case ErrorLevel:
+ _buffer.prepend("Error: ");
+ break;
+ default:
+ Q_ASSERT(_logLevel); // There should be no unknown log level
+ break;
+ }
+#ifndef HAVE_SYSLOG_H
_buffer.prepend(date.toString("yyyy-MM-dd hh:mm:ss "));
+#endif
log();
}
if(_logLevel < lvl) return;
+#ifdef HAVE_SYSLOG_H
+ if (Quassel::isOptionSet("syslog")) {
+ 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));
+ }
+#else
// if we can't open logfile we log to stdout
QTextStream out(stdout);
QFile file;
}
out << _buffer << endl;
if(file.isOpen()) file.close();
+#endif
}
cliParser->addOption("listen <address>[,<address[,...]]>", 0, "The address(es) quasselcore will listen on", "::,0.0.0.0");
cliParser->addOption("port <port>",'p', "The port quasselcore will listen at", QString("4242"));
cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
- cliParser->addOption("logfile <path>", 'l', "Path to logfile");
cliParser->addOption("loglevel <level>", 'L', "Loglevel Debug|Info|Warning|Error", "Info");
+#ifdef HAVE_SYSLOG_H
+ cliParser->addSwitch("syslog", 0, "Send the log to syslog.");
+#else
+ cliParser->addOption("logfile <path>", 'l', "Path to logfile");
+#endif
cliParser->addOption("select-backend <backendidentifier>", 0, "Starts an interactive session and switches your current storage backend to the new one. Attempts a merge if the new backend is uninitialized and the old backend supports migration. Otherwise prompts for new user credentials!");
cliParser->addSwitch("add-user", 0, "Starts an interactive session to add a new core user");
cliParser->addOption("change-userpass <username>", 0, "Starts an interactive session to change the password of the user identified by username");