From 5b3e42021401773bf18a20e73f95412cf269e56d Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Mon, 23 Aug 2021 21:54:04 +0200 Subject: [PATCH] Add executing code and cleanup header + Correct path mistake in Modcall writer --- core/include/logger/writer_sql.h | 5 ----- core/src/logger/writer_modcall.cpp | 2 +- core/src/logger/writer_sql.cpp | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/core/include/logger/writer_sql.h b/core/include/logger/writer_sql.h index 12db76c..53b8eb2 100644 --- a/core/include/logger/writer_sql.h +++ b/core/include/logger/writer_sql.h @@ -64,11 +64,6 @@ private: */ QSqlDatabase log_db; - /** - * @brief Filename of the logfile used. - */ - QFile l_logfile; - /** * @brief Directory where logfiles will be stored. */ diff --git a/core/src/logger/writer_modcall.cpp b/core/src/logger/writer_modcall.cpp index 59e2a82..68abc84 100644 --- a/core/src/logger/writer_modcall.cpp +++ b/core/src/logger/writer_modcall.cpp @@ -33,7 +33,7 @@ WriterModcall::WriterModcall(QObject* parent) : void WriterModcall::flush(const QString f_areaName, QQueue f_buffer) { - l_logfile.setFileName(QString("logs/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_areaName, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss")))); if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { QTextStream file_stream(&l_logfile); diff --git a/core/src/logger/writer_sql.cpp b/core/src/logger/writer_sql.cpp index 814929f..311bfc8 100644 --- a/core/src/logger/writer_sql.cpp +++ b/core/src/logger/writer_sql.cpp @@ -20,6 +20,16 @@ WriterSQL::WriterSQL(QObject* parent) : QObject(parent), DRIVER("QSQLITE") { + l_dir.setPath("logs/"); + if (!l_dir.exists()) { + l_dir.mkpath("."); + } + + l_dir.setPath("logs/database"); + if (!l_dir.exists()) { + l_dir.mkpath("."); + } + const QString db_filename = "logs/database/log.db"; QFileInfo db_info(db_filename); @@ -35,7 +45,7 @@ WriterSQL::WriterSQL(QObject* parent) : QSqlQuery create_chat_events_table("CREATE TABLE IF NOT EXISTS chat_events ('event_time' DATETIME DEFAULT CURRENT_TIMESTAMP, 'ipid' TEXT, 'room_name' TEXT,'event_type' TEXT, 'char_name' TEXT, 'ic_name' TEXT, 'message' TEXT NOT NULL);"); create_chat_events_table.exec(); - QSqlQuery create_connection_events_table("CREATE TABLE IF NOT EXISTS users ('event time' DATETIME DEFAULT CURRENT_TIMESTAMP, 'ipid' TEXT, 'ip_address' TEXT, 'hdid' TEXT);"); + QSqlQuery create_connection_events_table("CREATE TABLE IF NOT EXISTS connection_events ('event time' DATETIME DEFAULT CURRENT_TIMESTAMP, 'ipid' TEXT, 'ip_address' TEXT, 'hdid' TEXT);"); create_connection_events_table.exec(); } @@ -43,3 +53,12 @@ WriterSQL::~WriterSQL() { log_db.close(); } + +void WriterSQL::execLogScript(QSqlQuery query) +{ + query.exec(); + QSqlError error = query.lastError(); + if (error.isValid()) { + qDebug() << "Database Error:" + error.text(); + } +}