Browse Source

Close the global log targets on exit, flushing log files to disk

Victor Luchits 6 years ago
parent
commit
febbeaeeed
2 changed files with 12 additions and 3 deletions
  1. 11 3
      client/CMT.cpp
  2. 1 0
      server/CVCMIServer.cpp

+ 11 - 3
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);
 	};

+ 1 - 0
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;
 }