Commit e258f862 authored by Gavin Bisesi's avatar Gavin Bisesi
Browse files

Merge pull request #121 from woogerboy21/serverlog-filtering

Server log filtering
parents fb7de2ad f685bd2a
...@@ -5,6 +5,8 @@ logfile=server.log ...@@ -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 @@ ...@@ -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) ...@@ -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();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment