From cc3242320ba0e8a3b0edad816a11912d81f9b3bd Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 15 Aug 2022 15:06:46 +0000 Subject: [PATCH] Implement Log shutdown --- src/log.cc | 17 +++++++++++++++-- src/log.h | 1 + src/main.cc | 4 +--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/log.cc b/src/log.cc index 5687a79..50a34d3 100644 --- a/src/log.cc +++ b/src/log.cc @@ -24,12 +24,13 @@ bool LogNT::init(const std::string& tfileName, bool tenabled) { if (!tenabled) return true; - enabled = true; - fileName = tfileName; // Keep the filename for later? + if (enabled) return true; + fileName = tfileName; // Keep the filename for later? if (!fileName.compare("stdout")) { outstream = &std::cout; + enabled = true; return true; } @@ -37,9 +38,21 @@ bool LogNT::init(const std::string& tfileName, bool tenabled) logFile.open(fileName, std::ios_base::out | std::ios_base::app); if (!logFile.is_open()) return false; + enabled = true; return true; } +void LogNT::shutdown() +{ + if (!enabled) return; + + traceOnlyMode = false; + info("LOG", "Shutting down... bye!\n\n"); + + enabled = false; + if (logFile.is_open()) logFile.close(); +} + void LogNT::setTraceOnlyMode(bool t) { traceOnlyMode = t; diff --git a/src/log.h b/src/log.h index d477047..2a263db 100644 --- a/src/log.h +++ b/src/log.h @@ -48,6 +48,7 @@ class LogNT static LogNT* getInstance(); bool init(const std::string& fileName, bool enabled); + void shutdown(); void setTraceOnlyMode(bool); enum levels { TRACE, DEBUG, INFO, WARN, ERROR, CRIT }; diff --git a/src/main.cc b/src/main.cc index 38f0014..b3d9b26 100644 --- a/src/main.cc +++ b/src/main.cc @@ -296,9 +296,7 @@ void threadSignalReceiverFunction() if (loggerNT) { - loggerNT->info(TAG, "Log module shutting down... bye!\n\n"); -#warning loggerNT has no shutdown - //loggerNT->shutdown(); + loggerNT->shutdown(); delete loggerNT; } -- 2.39.5