Merge pull request #121 from woogerboy21/serverlog-filtering
Server log filtering
This commit is contained in:
commit
e258f8625a
2 changed files with 88 additions and 62 deletions
|
@ -5,6 +5,8 @@ logfile=server.log
|
||||||
name="My Cockatrice server"
|
name="My Cockatrice server"
|
||||||
id=1
|
id=1
|
||||||
number_pools=1
|
number_pools=1
|
||||||
|
writelog=1
|
||||||
|
logfilters=""
|
||||||
|
|
||||||
[servernetwork]
|
[servernetwork]
|
||||||
active=0
|
active=0
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QSettings>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
@ -44,13 +45,36 @@ void ServerLogger::logMessage(QString message, void *caller)
|
||||||
if (!logFile)
|
if (!logFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bufferMutex.lock();
|
|
||||||
QString callerString;
|
QString callerString;
|
||||||
if (caller)
|
if (caller)
|
||||||
callerString = QString::number((qulonglong) caller, 16) + " ";
|
callerString = QString::number((qulonglong) caller, 16) + " ";
|
||||||
|
|
||||||
|
//filter out all log entries based on values in configuration file
|
||||||
|
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
|
||||||
|
bool shouldWeWriteLog = settings->value("server/writelog").toBool();
|
||||||
|
QString logFilters = settings->value("server/logfilters").toString();
|
||||||
|
QStringList listlogFilters = logFilters.split(",", QString::SkipEmptyParts);
|
||||||
|
bool shouldWeSkipLine = false;
|
||||||
|
|
||||||
|
if (!shouldWeWriteLog)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!logFilters.trimmed().isEmpty()){
|
||||||
|
shouldWeSkipLine = true;
|
||||||
|
foreach(QString logFilter, listlogFilters){
|
||||||
|
if (message.contains(logFilter, Qt::CaseInsensitive)){
|
||||||
|
shouldWeSkipLine = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldWeSkipLine)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bufferMutex.lock();
|
||||||
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
||||||
bufferMutex.unlock();
|
bufferMutex.unlock();
|
||||||
|
|
||||||
emit sigFlushBuffer();
|
emit sigFlushBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue