From febbeaeeedecbc566371e61aa42adc5534efc195 Mon Sep 17 00:00:00 2001 From: Victor Luchits Date: Fri, 10 May 2019 12:35:28 +0300 Subject: [PATCH] Close the global log targets on exit, flushing log files to disk --- client/CMT.cpp | 14 +++++++++++--- server/CVCMIServer.cpp | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 8b99f4cd8..3a58a738c 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -108,6 +108,8 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen, int displayInde void playIntro(); static void mainLoop(); +static CBasicLogConfigurator *logConfig; + #ifndef VCMI_WINDOWS #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -230,8 +232,8 @@ int main(int argc, char * argv[]) console->start(); const bfs::path logPath = VCMIDirs::get().userCachePath() / "VCMI_Client_log.txt"; - CBasicLogConfigurator logConfig(logPath, console); - logConfig.configureDefault(); + logConfig = new CBasicLogConfigurator(logPath, console); + logConfig->configureDefault(); logGlobal->info(NAME); logGlobal->info("Creating console and configuring logger: %d ms", pomtime.getDiff()); logGlobal->info("The log file will be saved to %s", logPath); @@ -292,7 +294,7 @@ int main(int argc, char * argv[]) setSettingInteger("general/saveFrequency", "savefrequency", 1); // Initialize logging based on settings - logConfig.configure(); + logConfig->configure(); logGlobal->debug("settings = %s", settings.toJsonNode().toJson()); // Some basic data validation to produce better error messages in cases of incorrect install @@ -1434,6 +1436,12 @@ void handleQuit(bool ask) SDL_Quit(); } + if(logConfig != nullptr) { + logConfig->deconfigure(); + delete logConfig; + logConfig = nullptr; + } + std::cout << "Ending...\n"; exit(0); }; diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index dfcfefe4e..f392a6118 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -956,6 +956,7 @@ int main(int argc, char * argv[]) CAndroidVMHelper envHelper; envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "killServer"); #endif + logConfig.deconfigure(); vstd::clear_pointer(VLC); return 0; }