Activate logging for quasselcore.
[quassel.git] / src / common / main.cpp
index d7cd4e5..e72166d 100644 (file)
@@ -22,6 +22,7 @@
 #include <QString>
 #include <QTimer>
 #include <QTranslator>
+#include <QFile>
 
 #include "global.h"
 #include "logger.h"
@@ -64,8 +65,6 @@ int main(int argc, char **argv) {
   signal(SIGTERM, handle_signal);
   signal(SIGINT, handle_signal);
 
-  // Logger logger;
-
   Global::registerMetaTypes();
   Global::setupVersion();
 
@@ -86,6 +85,8 @@ int main(int argc, char **argv) {
 // put core-only arguments here
   Global::parser.addOption("port",'p',"The port quasselcore will listen at",QString("4242"));
   Global::parser.addSwitch("norestore", 'n', "Don't restore last core's state");
+  Global::parser.addOption("logfile",'l',"Path to logfile","./quassel.log");
+  Global::parser.addOption("loglevel",'L',"Loglevel Debug|Info|Warning|Error","Info");
 #endif // BUILD_QTUI
 #ifndef BUILD_CORE
 // put client-only arguments here
@@ -101,6 +102,21 @@ int main(int argc, char **argv) {
     return 1;
   }
 
+  /*
+   This is an initial check if logfile is writable since the warning would spam stdout if done
+   in current Logger implementation. Can be dropped whenever the logfile is only opened once.
+  */
+  if(Global::runMode != Global::ClientOnly) {
+    QFile logFile;
+    if(!Global::parser.value("logfile").isEmpty()) {
+      logFile.setFileName(Global::parser.value("logfile"));
+      if(!logFile.open(QIODevice::Append | QIODevice::Text))
+        qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead",qPrintable(logFile.fileName()));
+      logFile.close();
+    }
+    else qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead",qPrintable(logFile.fileName()));
+  }
+
   qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
 
   // Set up i18n support