Cleanup Logger

This commit is contained in:
Salanto 2021-09-10 23:51:38 +02:00
parent 4ac4dfdcc7
commit b22a83658a
6 changed files with 54 additions and 54 deletions

View File

@ -55,41 +55,41 @@ public slots:
/** /**
* @brief Adds an IC log entry to the area buffer and writes it to the respective log format. * @brief Adds an IC log entry to the area buffer and writes it to the respective log format.
*/ */
void logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, void logIC(const QString& f_char_name, const QString& f_ooc_name, const QString& f_ipid,
const QString& f_areaName, const QString &f_message); const QString& f_area_name, const QString &f_message);
/** /**
* @brief Adds an OOC log entry to the area buffer and writes it to the respective log format. * @brief Adds an OOC log entry to the area buffer and writes it to the respective log format.
*/ */
void logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, void logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString& f_message); const QString& f_area_name, const QString& f_message);
/** /**
* @brief Adds an login attempt to the area buffer and writes it to the respective log format. * @brief Adds an login attempt to the area buffer and writes it to the respective log format.
*/ */
void logLogin(const QString& f_charName, const QString& f_oocName, const QString& f_moderatorName, void logLogin(const QString& f_char_name, const QString& f_ooc_name, const QString& f_moderator_name,
const QString& f_ipid, const QString &f_areaName, const bool& f_success); const QString& f_ipid, const QString &f_area_name, const bool& f_success);
/** /**
* @brief Adds a command usage to the area buffer and writes it to the respective log format. * @brief Adds a command usage to the area buffer and writes it to the respective log format.
*/ */
void logCMD(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString f_command, void logCMD(const QString& f_char_name, const QString &f_ipid, const QString& f_ooc_name, const QString& f_command,
const QStringList f_args, const QString f_areaName); const QStringList& f_args, const QString& f_area_name);
/** /**
* @brief Adds a player kick to the area buffer and writes it to the respective log format. * @brief Adds a player kick to the area buffer and writes it to the respective log format.
*/ */
void logKick(const QString& f_moderator, const QString& f_targetIPID); void logKick(const QString& f_moderator, const QString& f_target_ipid);
/** /**
* @brief Adds a player ban to the area buffer and writes it to the respective log format. * @brief Adds a player ban to the area buffer and writes it to the respective log format.
*/ */
void logBan(const QString& f_moderator, const QString& f_targetIPID, const QString &f_duration); void logBan(const QString& f_moderator, const QString& f_target_ipid, const QString &f_duration);
/** /**
* @brief Adds a modcall event to the area buffer, also triggers modcall writing. * @brief Adds a modcall event to the area buffer, also triggers modcall writing.
*/ */
void logModcall(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString& f_areaName); void logModcall(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString& f_area_name);
/** /**
* @brief Logs any connection attempt to the server, wether sucessful or not. * @brief Logs any connection attempt to the server, wether sucessful or not.
@ -103,7 +103,7 @@ private:
* @param Name of the area which buffer is modified. * @param Name of the area which buffer is modified.
* @param Formatted QString to be added into the buffer. * @param Formatted QString to be added into the buffer.
*/ */
void updateAreaBuffer(const QString& f_areaName, const QString& f_logEntry); void updateAreaBuffer(const QString& f_areaName, const QString& f_log_entry);
/** /**
* @brief QMap of all available area buffers. * @brief QMap of all available area buffers.

View File

@ -55,7 +55,7 @@ public:
* @param Preformatted QString which will be written into the logfile * @param Preformatted QString which will be written into the logfile
* @param Area name of the target logfile. * @param Area name of the target logfile.
*/ */
void flush(const QString f_entry, const QString f_areaName); void flush(const QString f_entry, const QString f_area_name);
private: private:
/** /**

View File

@ -51,7 +51,7 @@ public:
* @param QQueue of the area that will be written into the logfile. * @param QQueue of the area that will be written into the logfile.
* @param Name of the area for the filename. * @param Name of the area for the filename.
*/ */
void flush(const QString f_areaName, QQueue<QString> f_buffer); void flush(const QString f_area_name, QQueue<QString> f_buffer);
private: private:
/** /**

View File

@ -44,36 +44,36 @@ ULogger::~ULogger()
} }
} }
void ULogger::logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, void ULogger::logIC(const QString& f_char_name, const QString& f_ooc_name, const QString& f_ipid,
const QString& f_areaName, const QString& f_message) const QString& f_area_name, const QString& f_message)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%5][IC][%2(%3)][%4]%6\n") QString l_logEntry = QStringLiteral("[%1][%5][IC][%2(%3)][%4]%6\n")
.arg(l_time, f_charName, f_oocName, f_ipid, f_areaName, f_message); .arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message);
updateAreaBuffer(f_areaName,l_logEntry); updateAreaBuffer(f_area_name,l_logEntry);
} }
void ULogger::logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, void ULogger::logOOC(const QString& f_char_name, const QString& f_ooc_name, const QString& f_ipid,
const QString& f_areaName, const QString& f_message) const QString& f_area_name, const QString& f_message)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%5][OOC][%2(%3)][%4]%6\n") QString l_logEntry = QStringLiteral("[%1][%5][OOC][%2(%3)][%4]%6\n")
.arg(l_time, f_charName, f_oocName, f_ipid, f_areaName, f_message); .arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message);
updateAreaBuffer(f_areaName,l_logEntry); updateAreaBuffer(f_area_name,l_logEntry);
} }
void ULogger::logLogin(const QString& f_charName, const QString& f_oocName, const QString& f_moderatorName, void ULogger::logLogin(const QString& f_char_name, const QString& f_ooc_name, const QString& f_moderator_name,
const QString& f_ipid, const QString& f_areaName, const bool &f_success) const QString& f_ipid, const QString& f_area_name, const bool &f_success)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_success = f_success ? "SUCCESS][" + f_moderatorName : "FAILED][" + f_moderatorName; QString l_success = f_success ? "SUCCESS][" + f_moderator_name : "FAILED][" + f_moderator_name;
QString l_logEntry = QStringLiteral("[%1][LOGIN][%2][%3][%4(%5)]\n") QString l_logEntry = QStringLiteral("[%1][LOGIN][%2][%3][%4(%5)]\n")
.arg(l_time, l_success, f_ipid, f_charName, f_oocName); .arg(l_time, l_success, f_ipid, f_char_name, f_ooc_name);
updateAreaBuffer(f_areaName, l_logEntry); updateAreaBuffer(f_area_name, l_logEntry);
} }
void ULogger::logCMD(const QString& f_charName,const QString& f_ipid, const QString& f_oocName, const QString f_command, void ULogger::logCMD(const QString& f_char_name,const QString& f_ipid, const QString& f_ooc_name, const QString& f_command,
const QStringList f_args, const QString f_areaName) const QStringList& f_args, const QString& f_area_name)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry; QString l_logEntry;
@ -81,48 +81,48 @@ void ULogger::logCMD(const QString& f_charName,const QString& f_ipid, const QStr
// These must be filtered out // These must be filtered out
if (f_command == "login") { if (f_command == "login") {
l_logEntry = QStringLiteral("[%1][%2][LOGIN][%5][%3(%4)]\n") l_logEntry = QStringLiteral("[%1][%2][LOGIN][%5][%3(%4)]\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
} }
else if (f_command == "rootpass") { else if (f_command == "rootpass") {
l_logEntry = QStringLiteral("[%1][%2][ROOTPASS][%5][%3(%4)]\n") l_logEntry = QStringLiteral("[%1][%2][ROOTPASS][%5][%3(%4)]\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
} }
else if (f_command == "adduser" && !f_args.isEmpty()) { else if (f_command == "adduser" && !f_args.isEmpty()) {
l_logEntry = QStringLiteral("[%1][%2][USERADD][%6][%3(%4)]%5\n") l_logEntry = QStringLiteral("[%1][%2][USERADD][%6][%3(%4)]%5\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_args.at(0), f_ipid); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_args.at(0), f_ipid);
} }
else { else {
l_logEntry = QStringLiteral("[%1][%2][CMD][%7][%3(%4)]/%5 %6\n") l_logEntry = QStringLiteral("[%1][%2][CMD][%7][%3(%4)]/%5 %6\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_command, f_args.join(" "), f_ipid); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_command, f_args.join(" "), f_ipid);
} }
updateAreaBuffer(f_areaName,l_logEntry); updateAreaBuffer(f_area_name,l_logEntry);
} }
void ULogger::logKick(const QString& f_moderator, const QString& f_targetIPID) void ULogger::logKick(const QString& f_moderator, const QString& f_target_ipid)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%2][KICK][%3]\n") QString l_logEntry = QStringLiteral("[%1][%2][KICK][%3]\n")
.arg(l_time, f_moderator, f_targetIPID); .arg(l_time, f_moderator, f_target_ipid);
updateAreaBuffer("SERVER",l_logEntry); updateAreaBuffer("SERVER",l_logEntry);
} }
void ULogger::logBan(const QString &f_moderator, const QString &f_targetIPID, const QString &f_duration) void ULogger::logBan(const QString &f_moderator, const QString &f_target_ipid, const QString &f_duration)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%2][BAN][%3][%4]\n") QString l_logEntry = QStringLiteral("[%1][%2][BAN][%3][%4]\n")
.arg(l_time, f_moderator, f_targetIPID, f_duration); .arg(l_time, f_moderator, f_target_ipid, f_duration);
updateAreaBuffer("SERVER",l_logEntry); updateAreaBuffer("SERVER",l_logEntry);
} }
void ULogger::logModcall(const QString &f_charName, const QString &f_ipid, const QString &f_oocName, const QString &f_areaName) void ULogger::logModcall(const QString &f_char_name, const QString &f_ipid, const QString &f_oocName, const QString &f_area_name)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEvent = QStringLiteral("[%1][%2][MODCALL][%5][%3(%4)]\n") QString l_logEvent = QStringLiteral("[%1][%2][MODCALL][%5][%3(%4)]\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid); .arg(l_time, f_area_name, f_char_name, f_oocName, f_ipid);
updateAreaBuffer(f_areaName, l_logEvent); updateAreaBuffer(f_area_name, l_logEvent);
if (ConfigManager::loggingType() == DataTypes::LogType::MODCALL) { if (ConfigManager::loggingType() == DataTypes::LogType::MODCALL) {
writerModcall->flush(f_areaName, buffer(f_areaName)); writerModcall->flush(f_area_name, buffer(f_area_name));
} }
} }
@ -134,28 +134,28 @@ void ULogger::logConnectionAttempt(const QString& f_ip_address, const QString& f
updateAreaBuffer("SERVER",l_logEntry); updateAreaBuffer("SERVER",l_logEntry);
} }
void ULogger::updateAreaBuffer(const QString& f_areaName, const QString& f_logEntry) void ULogger::updateAreaBuffer(const QString& f_area_name, const QString& f_log_entry)
{ {
QQueue<QString>l_buffer = m_bufferMap.value(f_areaName); QQueue<QString>l_buffer = m_bufferMap.value(f_area_name);
if (l_buffer.length() <= ConfigManager::logBuffer()) { if (l_buffer.length() <= ConfigManager::logBuffer()) {
l_buffer.enqueue(f_logEntry); l_buffer.enqueue(f_log_entry);
} }
else { else {
l_buffer.dequeue(); l_buffer.dequeue();
l_buffer.enqueue(f_logEntry); l_buffer.enqueue(f_log_entry);
} }
m_bufferMap.insert(f_areaName, l_buffer); m_bufferMap.insert(f_area_name, l_buffer);
if (ConfigManager::loggingType() == DataTypes::LogType::FULL){ if (ConfigManager::loggingType() == DataTypes::LogType::FULL){
writerFull->flush(f_logEntry); writerFull->flush(f_log_entry);
} }
if (ConfigManager::loggingType() == DataTypes::LogType::FULLAREA) { if (ConfigManager::loggingType() == DataTypes::LogType::FULLAREA) {
writerFull->flush(f_logEntry, f_areaName); writerFull->flush(f_log_entry, f_area_name);
} }
} }
QQueue<QString> ULogger::buffer(const QString& f_areaName) QQueue<QString> ULogger::buffer(const QString& f_area_name)
{ {
return m_bufferMap.value(f_areaName); return m_bufferMap.value(f_area_name);
} }

View File

@ -37,9 +37,9 @@ void WriterFull::flush(const QString f_entry)
l_logfile.close(); l_logfile.close();
} }
void WriterFull::flush(const QString f_entry, const QString f_areaName) void WriterFull::flush(const QString f_entry, const QString f_area_name)
{ {
l_logfile.setFileName(QString("logs/%1_%2.log").arg(f_areaName, QDate::currentDate().toString("yyyy-MM-dd"))); l_logfile.setFileName(QString("logs/%1_%2.log").arg(f_area_name, QDate::currentDate().toString("yyyy-MM-dd")));
if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream file_stream(&l_logfile); QTextStream file_stream(&l_logfile);

View File

@ -31,9 +31,9 @@ WriterModcall::WriterModcall(QObject* parent) :
} }
} }
void WriterModcall::flush(const QString f_areaName, QQueue<QString> f_buffer) void WriterModcall::flush(const QString f_area_name, QQueue<QString> f_buffer)
{ {
l_logfile.setFileName(QString("logs/modcall/report_%1_%2.log").arg(f_areaName, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss")))); l_logfile.setFileName(QString("logs/modcall/report_%1_%2.log").arg(f_area_name, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"))));
if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream file_stream(&l_logfile); QTextStream file_stream(&l_logfile);