diff options
author | HappyDOGE <28511119+HappyDOGE@users.noreply.github.com> | 2022-01-16 13:12:50 +0300 |
---|---|---|
committer | HappyDOGE <28511119+HappyDOGE@users.noreply.github.com> | 2022-01-16 13:12:50 +0300 |
commit | 8e9338805062f53be1135d49b6021bd3ab8a220f (patch) | |
tree | 6c56076795299c601ed6afae5bac973b61585774 /NorthstarDedicatedTest/logging.cpp | |
parent | 4f0e396e9774dad1eb03aa54f65c64da4b0e3a60 (diff) | |
parent | d4d4e489e4a1435e1df3cd1a1e3666e7ae713829 (diff) | |
download | NorthstarLauncher-8e9338805062f53be1135d49b6021bd3ab8a220f.tar.gz NorthstarLauncher-8e9338805062f53be1135d49b6021bd3ab8a220f.zip |
merge with upstream
Diffstat (limited to 'NorthstarDedicatedTest/logging.cpp')
-rw-r--r-- | NorthstarDedicatedTest/logging.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index a7e522dc..235bfe2e 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -10,6 +10,27 @@ #include <Psapi.h> #include <minidumpapiset.h> + +// This needs to be called after hooks are loaded so we can access the command line args +void CreateLogFiles() +{ + if (strstr(GetCommandLineA(), "-disablelogs")) + { + spdlog::default_logger()->set_level(spdlog::level::off); + } + else + { + // todo: might be good to delete logs that are too old + time_t time = std::time(nullptr); + tm currentTime = *std::localtime(&time); + std::stringstream stream; + + stream << std::put_time(¤tTime, "R2Northstar/logs/nslog%Y-%m-%d %H-%M-%S.txt"); + spdlog::default_logger()->sinks().push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(stream.str(), false)); + spdlog::flush_on(spdlog::level::info); + } +} + long __stdcall ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) { static bool logged = false; @@ -154,7 +175,7 @@ long __stdcall ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) time_t time = std::time(nullptr); tm currentTime = *std::localtime(&time); std::stringstream stream; - stream << std::put_time(¤tTime, "R2Northstar/logs/nsdump%d-%m-%Y %H-%M-%S.dmp"); + stream << std::put_time(¤tTime, "R2Northstar/logs/nsdump%Y-%m-%d %H-%M-%S.dmp"); auto hMinidumpFile = CreateFileA(stream.str().c_str(), GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hMinidumpFile) @@ -171,8 +192,7 @@ long __stdcall ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) spdlog::error("Failed to write minidump file {}!", stream.str()); if (!IsDedicated()) - MessageBoxA(0, "Northstar has crashed! A crash log and dump can be found in R2Northstar/logs", "Northstar has crashed!", MB_ICONERROR | MB_OK); - + MessageBoxA(0, "Northstar has crashed! Crash info can be found in R2Northstar/logs", "Northstar has crashed!", MB_ICONERROR | MB_OK); } logged = true; @@ -187,20 +207,7 @@ void InitialiseLogging() AllocConsole(); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); - spdlog::default_logger()->set_pattern("[%H:%M:%S] [%l] %v"); - spdlog::flush_on(spdlog::level::info); - - // log file stuff - // generate log file, format should be nslog%d-%m-%Y %H-%M-%S.txt in gamedir/R2Northstar/logs - // todo: might be good to delete logs that are too old - time_t time = std::time(nullptr); - tm currentTime = *std::localtime(&time); - std::stringstream stream; - stream << std::put_time(¤tTime, "R2Northstar/logs/nslog%d-%m-%Y %H-%M-%S.txt"); - - // create logger - spdlog::default_logger()->sinks().push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(stream.str(), false)); } ConVar* Cvar_spewlog_enable; |