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] 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(); }