updated code structure
cleaned code structure up for clarity
This commit is contained in:
parent
236e0a4197
commit
46ceeadbbd
1 changed files with 29 additions and 19 deletions
|
@ -5,11 +5,13 @@
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
ServerLogger::ServerLogger(bool _logToConsole, QObject *parent)
|
ServerLogger::ServerLogger(bool _logToConsole, QObject *parent)
|
||||||
: QObject(parent), logToConsole(_logToConsole), flushRunning(false)
|
: QObject(parent), logToConsole(_logToConsole), flushRunning(false)
|
||||||
|
@ -51,37 +53,45 @@ void ServerLogger::logMessage(QString message, void *caller)
|
||||||
|
|
||||||
//filter out all log entries based on loglevel value in configuration file
|
//filter out all log entries based on loglevel value in configuration file
|
||||||
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
|
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
|
||||||
int found = 0; int capture = 0; int loglevel = 0;
|
int found = 0; int capture = 0; int loglevel = 0; list<string> lst_str;
|
||||||
loglevel = settings->value("server/loglevel").toInt();
|
loglevel = settings->value("server/loglevel").toInt();
|
||||||
|
|
||||||
|
|
||||||
switch (loglevel)
|
switch (loglevel)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
capture = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
||||||
// filter message log data
|
// filter message log data
|
||||||
found = message.indexOf("Adding room: ID=", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Adding room: ID=");
|
||||||
found = message.indexOf("Starting status update clock", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Starting status update clock");
|
||||||
found = message.indexOf("Starting server on port", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Starting server on port");
|
||||||
found = message.indexOf("Server listening.", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Server listening.");
|
||||||
found = message.indexOf("Server::loginUser:", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Server::loginUser:");
|
||||||
found = message.indexOf("Server::removeClient:", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Server::removeClient:");
|
||||||
found = message.indexOf("Command_Login.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Command_Login.ext");
|
||||||
found = message.indexOf("Command_RoomSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Command_RoomSay.ext");
|
||||||
found = message.indexOf("Command_Message.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Command_Message.ext");
|
||||||
found = message.indexOf("Command_GameSay.ext", Qt::CaseInsensitive); if (found != -1){ capture = 1; }
|
lst_str.push_back("Command_GameSay.ext");
|
||||||
if (capture != 0){
|
for (list<string>::iterator i = lst_str.begin(); i != lst_str.end(); i++)
|
||||||
bufferMutex.lock();
|
{
|
||||||
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
if(message.indexOf((*i).c_str(), Qt::CaseInsensitive) != -1) {
|
||||||
bufferMutex.unlock();
|
capture = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
bufferMutex.lock();
|
capture = 1;
|
||||||
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
}
|
||||||
bufferMutex.unlock();
|
|
||||||
|
if (capture != 0){
|
||||||
|
bufferMutex.lock();
|
||||||
|
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
|
||||||
|
bufferMutex.unlock();
|
||||||
}
|
}
|
||||||
emit sigFlushBuffer();
|
emit sigFlushBuffer();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue