added server log filtering
added log filtering based on configuration file setting 0 = log everything 1 = log nothing 2 = chat logging only
This commit is contained in:
parent
ea08fe168c
commit
5592346979
1 changed files with 36 additions and 4 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDateTime>
|
||||
#include <QSettings>
|
||||
#include <iostream>
|
||||
#ifdef Q_OS_UNIX
|
||||
# include <sys/types.h>
|
||||
|
@ -44,13 +45,44 @@ void ServerLogger::logMessage(QString message, void *caller)
|
|||
if (!logFile)
|
||||
return;
|
||||
|
||||
bufferMutex.lock();
|
||||
QString callerString;
|
||||
if (caller)
|
||||
callerString = QString::number((qulonglong) caller, 16) + " ";
|
||||
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
||||
bufferMutex.unlock();
|
||||
|
||||
|
||||
//filter out all log entries based on loglevel value in configuration file
|
||||
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
|
||||
int found = 0; int capture = 0; int loglevel = 0;
|
||||
loglevel = settings->value("server/loglevel").toInt();
|
||||
switch (loglevel)
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
// filter message log data
|
||||
found = message.indexOf("Adding room: ID=", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Starting status update clock", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Starting server on port", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Server listening.", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Server::loginUser:", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Server::removeClient:", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Command_Login.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Command_RoomSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Command_Message.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
found = message.indexOf("Command_GameSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
||||
if (capture != 0){
|
||||
bufferMutex.lock();
|
||||
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
||||
bufferMutex.unlock();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
bufferMutex.lock();
|
||||
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
||||
bufferMutex.unlock();
|
||||
}
|
||||
emit sigFlushBuffer();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue