From 8ad57633ae1122c94b82550101e32aa99d72e768 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Fri, 10 Sep 2021 15:59:10 +0200 Subject: [PATCH] Implement simple area sorted logs --- core/include/data_types.h | 1 + core/include/logger/writer_full.h | 7 +++++++ core/src/logger/u_logger.cpp | 9 +++++++++ core/src/logger/writer_full.cpp | 11 +++++++++++ 4 files changed, 28 insertions(+) diff --git a/core/include/data_types.h b/core/include/data_types.h index 4983f86..f6385e8 100644 --- a/core/include/data_types.h +++ b/core/include/data_types.h @@ -42,6 +42,7 @@ public: enum class LogType { MODCALL, FULL, + FULLAREA }; Q_ENUM(LogType) }; diff --git a/core/include/logger/writer_full.h b/core/include/logger/writer_full.h index ce1677c..33abe87 100644 --- a/core/include/logger/writer_full.h +++ b/core/include/logger/writer_full.h @@ -50,6 +50,13 @@ public: */ void flush(const QString f_entry); + /** + * @brief Writes log entry into area seperated logfiles. + * @param Preformatted QString which will be written into the logfile + * @param Area name of the target logfile. + */ + void flushArea(const QString f_entry, const QString f_areaName); + private: /** * @brief Filename of the logfile used. This will always be the time the server starts up. diff --git a/core/src/logger/u_logger.cpp b/core/src/logger/u_logger.cpp index 5e2bcea..badc6d8 100644 --- a/core/src/logger/u_logger.cpp +++ b/core/src/logger/u_logger.cpp @@ -27,6 +27,9 @@ ULogger::ULogger(QObject* parent) : case DataTypes::LogType::FULL : writerFull = new WriterFull; break; + case DataTypes::LogType::FULLAREA : + writerFull = new WriterFull; + break; } } @@ -39,6 +42,9 @@ ULogger::~ULogger() case DataTypes::LogType::FULL : writerFull->deleteLater(); break; + case DataTypes::LogType::FULLAREA : + writerFull->deleteLater(); + break; } } @@ -148,6 +154,9 @@ void ULogger::updateAreaBuffer(const QString& f_areaName, const QString& f_logEn if (ConfigManager::loggingType() == DataTypes::LogType::FULL){ writerFull->flush(f_logEntry); } + if (ConfigManager::loggingType() == DataTypes::LogType::FULLAREA) { + writerFull->flushArea(f_logEntry, f_areaName); + } } QQueue ULogger::buffer(const QString& f_areaName) diff --git a/core/src/logger/writer_full.cpp b/core/src/logger/writer_full.cpp index 613b6c4..6a6827c 100644 --- a/core/src/logger/writer_full.cpp +++ b/core/src/logger/writer_full.cpp @@ -30,6 +30,17 @@ void WriterFull::flush(const QString f_entry) { l_logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd"))); + if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { + QTextStream file_stream(&l_logfile); + file_stream << f_entry; + } + l_logfile.close(); +} + +void WriterFull::flushArea(const QString f_entry, const QString f_areaName) +{ + l_logfile.setFileName(QString("logs/%1_%2.log").arg(f_areaName, QDate::currentDate().toString("yyyy-MM-dd"))); + if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { QTextStream file_stream(&l_logfile); file_stream << f_entry;