From 6511e13585d99d3c61805fcfc4b7bf467573a8a2 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sat, 3 Apr 2021 20:35:21 -0500 Subject: [PATCH 1/3] Save server logs to logs/ instead of config/ --- src/logger.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/logger.cpp b/src/logger.cpp index 0b5f333..0849f18 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -88,10 +88,14 @@ void Logger::addEntry(QString entry) void Logger::flush() { + QDir dir("logs/"); + if (!dir.exists()) { + dir.mkpath("."); + } // raiden suggested this, but idk if i want to use it // QString time = QDateTime::currentDateTime().toString("ddd mm/dd/yy hh:mm:ss"); // QString filename = QStringLiteral("reports/%1/%2.log").arg(area->name).arg(time); - QFile logfile("config/server.log"); + QFile logfile("logs/server.log"); if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { QTextStream file_stream(&logfile); while (!buffer.isEmpty()) From d51203e634b41fb6ccf1240780a60c23861e099d Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sun, 4 Apr 2021 02:47:36 -0500 Subject: [PATCH 2/3] Add configurable logging options --- bin/config_sample/config.ini | 1 + src/logger.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini index eaf63ba..aea2eee 100644 --- a/bin/config_sample/config.ini +++ b/bin/config_sample/config.ini @@ -15,6 +15,7 @@ webao_port=27017 auth=simple modpass=changeme logbuffer=500 +logger=modcall [Dice] max_value=100 diff --git a/src/logger.cpp b/src/logger.cpp index 0849f18..76458ea 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -77,8 +77,14 @@ QString Logger::buildEntry(AOClient *client, QString type, QString message) void Logger::addEntry(QString entry) { + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + QString log_type = config.value("logging", "modcall").toString(); if (buffer.length() < max_length) { buffer.enqueue(entry); + if (log_type == "full") { + flush(); + } } else { buffer.dequeue(); @@ -95,11 +101,20 @@ void Logger::flush() // raiden suggested this, but idk if i want to use it // QString time = QDateTime::currentDateTime().toString("ddd mm/dd/yy hh:mm:ss"); // QString filename = QStringLiteral("reports/%1/%2.log").arg(area->name).arg(time); - QFile logfile("logs/server.log"); - if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + QString log_type = config.value("logging", "modcall").toString(); + QFile logfile; + if (log_type == "modcall") { + logfile.setFileName(QString("logs/report_%1_%2.log").arg((area->name), (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss")))); + } + else if (log_type == "full") { + logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd"))); + } + if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { QTextStream file_stream(&logfile); while (!buffer.isEmpty()) file_stream << buffer.dequeue(); - } + } logfile.close(); } From e3e3315da648dcf3f14cc781aec30b0462df1987 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Sun, 4 Apr 2021 03:16:19 -0500 Subject: [PATCH 3/3] remove raiden --- src/logger.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/logger.cpp b/src/logger.cpp index 76458ea..4dca853 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -98,9 +98,7 @@ void Logger::flush() if (!dir.exists()) { dir.mkpath("."); } - // raiden suggested this, but idk if i want to use it - // QString time = QDateTime::currentDateTime().toString("ddd mm/dd/yy hh:mm:ss"); - // QString filename = QStringLiteral("reports/%1/%2.log").arg(area->name).arg(time); + QSettings config("config/config.ini", QSettings::IniFormat); config.beginGroup("Options"); QString log_type = config.value("logging", "modcall").toString();