diff --git a/scripts/murmur.ini b/scripts/murmur.ini index 36038ac78..35b10b003 100644 --- a/scripts/murmur.ini +++ b/scripts/murmur.ini @@ -20,11 +20,15 @@ database= #dbHost= #dbPort= -# Murmur defaults to join the session D-Bus. If you wish to use another bus, please +# Murmur defaults to not using D-Bus. If you wish to use dbus, please # specify so here. # #dbus=session +# Murmur default to logging to murmur.log. If you leave this blank, +# murmur will log to the console (linux) or through message boxes (win32). +#logfile=murmur.log + # Password to join server serverpassword= diff --git a/src/murmur/Server.cpp b/src/murmur/Server.cpp index c0d3749f0..b61710ab0 100644 --- a/src/murmur/Server.cpp +++ b/src/murmur/Server.cpp @@ -66,11 +66,16 @@ ServerParams::ServerParams() { iDBPort = 0; qsDBDriver = "QSQLITE"; qsDBus = "session"; + qsLogfile = "murmur.log"; } void ServerParams::read(QString fname) { if (fname.isEmpty()) fname = "murmur.ini"; + else { + if (! QFile(fname).exists()) + qFatal("Specified ini file %s could not be opened", qPrintable(fname)); + } QSettings qs(fname, QSettings::IniFormat); qsPassword = qs.value("serverpassword", qsPassword).toString(); @@ -91,6 +96,8 @@ void ServerParams::read(QString fname) { iDBPort = qs.value("dbPort", iDBPort).toInt(); qsDBus = qs.value("dbus", qsDBus).toString(); + + qsLogfile = qs.value("logfile", qsLogfile).toString(); } BandwidthRecord::BandwidthRecord() { @@ -145,7 +152,7 @@ void UDPThread::udpReady() { Peer p(senderAddr, senderPort); Connection *source = qhPeerConnections.value(p); - + if (!source || (source != g_sServer->qmConnections.value(msg->sPlayerId))) { source = g_sServer->qmConnections.value(msg->sPlayerId); if (! source || ! (source->peerAddress() == senderAddr)) { @@ -318,11 +325,9 @@ void Server::log(QString s, Connection *c) { iid = p->iId; name = p->qsName; } - qWarning("[%s] <%d:%s(%d)> %s", QDateTime::currentDateTime().toString(Qt::ISODate).toAscii().constData(), - id, name.toAscii().constData(), iid, s.toAscii().constData()); + qWarning("<%d:%s(%d)> %s", id, qPrintable(name), iid, qPrintable(s)); } else { - qWarning("[%s] %s", QDateTime::currentDateTime().toString(Qt::ISODate).toAscii().constData(), - s.toAscii().constData()); + qWarning("%s", qPrintable(s)); } } diff --git a/src/murmur/Server.h b/src/murmur/Server.h index f2ed6277a..e4e3b0285 100644 --- a/src/murmur/Server.h +++ b/src/murmur/Server.h @@ -140,6 +140,8 @@ struct ServerParams { QString qsDBus; + QString qsLogfile; + ServerParams(); void read(QString fname = QString("murmur.ini")); }; diff --git a/src/murmur/ServerDB.cpp b/src/murmur/ServerDB.cpp index 18bd9ca1f..7a5837032 100644 --- a/src/murmur/ServerDB.cpp +++ b/src/murmur/ServerDB.cpp @@ -111,8 +111,6 @@ ServerDB::ServerDB() { if (! found) { QSqlError e = db.lastError(); qFatal("ServerDB: Failed initialization: %s",qPrintable(e.text())); - } else { - qWarning("ServerDB: Opened successfully"); } QSqlQuery query; diff --git a/src/murmur/murmur.cpp b/src/murmur/murmur.cpp index a1316c390..d3359e66d 100644 --- a/src/murmur/murmur.cpp +++ b/src/murmur/murmur.cpp @@ -39,8 +39,39 @@ #include "DBus.h" extern Server *g_sServer; - MurmurDBus *dbus; +QFile *logfile; + +static void murmurMessageOutput(QtMsgType type, const char *msg) +{ + + char c; + switch (type) { + case QtDebugMsg: + c='D'; + break; + case QtWarningMsg: + c='W'; + break; + case QtFatalMsg: + c='F'; + break; + default: + c='X'; + } + QString m= QString::fromLatin1("<%1>%2 %3\n").arg(QChar::fromLatin1(c)).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(msg); + + if (! logfile || ! logfile->isOpen()) { +#ifdef Q_OS_UNIX + fprintf(stderr, "%s", qPrintable(msg)); +#else + ::MessageBoxA(NULL, qPrintable(msg), "Murmur", MB_OK | MB_ICONWARNING); +#endif + } else { + logfile->write(m.toUtf8()); + logfile->flush(); + } +} int main(int argc, char **argv) { @@ -55,7 +86,6 @@ int main(int argc, char **argv) exit(0); } #endif - int res; QCoreApplication a(argc, argv); @@ -70,6 +100,10 @@ int main(int argc, char **argv) QString inifile; QString supw; + bool detach = true; + + qInstallMsgHandler(murmurMessageOutput); + for(int i=1;i] [-supw ]",argv[0]); - qWarning(" -ini Specify ini file to use."); - qWarning(" -supw Set password for 'SuperUser' account."); - qWarning("If no inifile is provided, murmur will search for one in "); - qFatal("default locations."); + qFatal("Usage: %s [-ini ] [-supw ]\n" + " -ini Specify ini file to use.\n" + " -supw Set password for 'SuperUser' account.\n" + " -fg Don't detach from console [Linux only].\n" + "If no inifile is provided, murmur will search for one in \n" + "default locations.",argv[0]); } else { qFatal("Unknown argument %s", argv[i]); } @@ -99,8 +136,29 @@ int main(int argc, char **argv) qFatal("Superuser password set"); } + if (! g_sp.qsLogfile.isEmpty()) { + logfile = new QFile(g_sp.qsLogfile); + if (! logfile->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { + delete logfile; + logfile = NULL; + qWarning("Failed to open logfile %s. Will not detach.",qPrintable(g_sp.qsLogfile)); + detach = false; + } + } else { + detach = false; + } #ifdef Q_OS_UNIX + if (detach) { + if (fork() != 0) { + _exit(0); + } + setsid(); + if (fork() != 0) { + _exit(0); + } + } + MurmurDBus::registerTypes(); #endif dbus=new MurmurDBus(a); diff --git a/src/murmur/murmur.pro b/src/murmur/murmur.pro index 78b514715..91ccbc7f8 100644 --- a/src/murmur/murmur.pro +++ b/src/murmur/murmur.pro @@ -1,7 +1,7 @@ include(../mumble.pri) TEMPLATE =app -CONFIG += network console +CONFIG += network CONFIG(static) { QMAKE_LFLAGS += -static }