Commit 91a96643 authored by woogerboy21's avatar woogerboy21
Browse files

updated filtering code

rewrote filtering code to allow for user input
code only filters on single string at the moment (still needs updated).
parent ec00bdeb
...@@ -5,13 +5,11 @@ ...@@ -5,13 +5,11 @@
#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)
...@@ -53,48 +51,25 @@ void ServerLogger::logMessage(QString message, void *caller) ...@@ -53,48 +51,25 @@ 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 capture = 0; list<string> lst_str; bool shouldWeWriteLog = settings->value("server/writelog").toBool();
int loglevel = settings->value("server/loglevel").toInt(); //allowedLogStatements << "Adding room: ID=" << "Starting status update clock" << "Starting server on port" <<
if (!loglevel) // "Server listening." << "Server::loginUser:" << "Server::removeClient:" << "Command_Login.ext" <<
loglevel = 999; // "Command_RoomSay.ext" << "Command_Message.ext" << "Command_GameSay.ext";
switch (loglevel) if (shouldWeWriteLog){
{ QString logFilters = settings->value("server/logfilters").toString();
case 1: bool shouldWeSkipLine = false;
capture = 0; if (!logFilters.trimmed().isEmpty())
break; shouldWeSkipLine = !message.contains(logFilters);
case 2: if (shouldWeSkipLine)
// filter message log data return;
lst_str.push_back("Adding room: ID=");
lst_str.push_back("Starting status update clock");
lst_str.push_back("Starting server on port");
lst_str.push_back("Server listening.");
lst_str.push_back("Server::loginUser:");
lst_str.push_back("Server::removeClient:");
lst_str.push_back("Command_Login.ext");
lst_str.push_back("Command_RoomSay.ext");
lst_str.push_back("Command_Message.ext");
lst_str.push_back("Command_GameSay.ext");
for (list<string>::iterator i = lst_str.begin(); i != lst_str.end(); i++)
{
if(message.indexOf((*i).c_str(), Qt::CaseInsensitive) != -1) {
capture = 1;
break;
}
}
break;
default:
capture = 1;
}
if (capture != 0){
bufferMutex.lock(); bufferMutex.lock();
buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message); buffer.append(QDateTime::currentDateTime().toString() + " " + callerString + message);
bufferMutex.unlock(); bufferMutex.unlock();
emit sigFlushBuffer();
} }
emit sigFlushBuffer();
} }
void ServerLogger::flushBuffer() void ServerLogger::flushBuffer()
......
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