From 21ad77d9f25bbdfa3fdeb653afaceb6532d6919b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 2 May 2022 17:21:19 +0100 Subject: Flush logs every 15 minutes to avoid losing data. --- src/logging.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/logging.cpp') diff --git a/src/logging.cpp b/src/logging.cpp index 37a38fae6..c5d295bd8 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -44,12 +44,16 @@ const char* Log::LevelToString(Log::Level level) } Log::FileMethod::FileMethod(const std::string& n, FILE* fh, unsigned long fl, bool ac) - : autoclose(ac) + : Timer(15*60) + , autoclose(ac) , file(fh) , flush(fl) , name(n) { + if (flush > 1) + ServerInstance->Timers.AddTimer(this); } + Log::FileMethod::~FileMethod() { if (autoclose) @@ -84,6 +88,12 @@ void Log::FileMethod::OnLog(Level level, const std::string& type, const std::str throw CoreException(InspIRCd::Format("Unable to write to %s: %s", name.c_str(), strerror(errno))); } +bool Log::FileMethod::Tick() +{ + fflush(file); + return true; +} + Log::Engine::Engine(Module* Creator, const std::string& Name) : DataProvider(Creator, "log/" + Name) { -- cgit v1.3.1-10-gc9f91