From 9b514e53388a22458ef4c1bbe6ad975f49548463 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Wed, 29 Dec 2021 00:42:44 +0100 Subject: Make timestamp year-month-day instead of day-month-year --- NorthstarDedicatedTest/logging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'NorthstarDedicatedTest/logging.cpp') diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index 09ae6961..fb5a11fc 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -176,12 +176,12 @@ void InitialiseLogging() 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 + // generate log file, format should be nslog%Y-%m-%d %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"); + stream << std::put_time(¤tTime, "R2Northstar/logs/nslog%Y-%m-%d %H-%M-%S.txt"); // create logger spdlog::default_logger()->sinks().push_back(std::make_shared(stream.str(), false)); -- cgit v1.2.3 From d545b3d7d4eb02a84fa7cb9ce1ff591c81b08707 Mon Sep 17 00:00:00 2001 From: Barichello Date: Fri, 14 Jan 2022 00:49:27 -0300 Subject: Update date format in dump files --- NorthstarDedicatedTest/logging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'NorthstarDedicatedTest/logging.cpp') diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index c5c5ea19..2592cb3e 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -154,7 +154,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) -- cgit v1.2.3 From c9d66513a85d5325d3d002ca16c82d8302ec0ea2 Mon Sep 17 00:00:00 2001 From: Barichello Date: Fri, 14 Jan 2022 10:34:03 -0300 Subject: Add command line arg to disable logs --- NorthstarDedicatedTest/dllmain.cpp | 3 +-- NorthstarDedicatedTest/logging.cpp | 37 ++++++++++++++++++++++--------------- NorthstarDedicatedTest/logging.h | 1 + 3 files changed, 24 insertions(+), 17 deletions(-) (limited to 'NorthstarDedicatedTest/logging.cpp') diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 856b2992..eb4b8936 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -76,9 +76,8 @@ bool InitialiseNorthstar() curl_global_init_mem(CURL_GLOBAL_DEFAULT, _malloc_base, _free_base, _realloc_base, _strdup_base, _calloc_base); InitialiseLogging(); - - // apply initial hooks InstallInitialHooks(); + CreateLogFiles(); InitialiseInterfaceCreationHooks(); AddDllLoadCallback("tier0.dll", InitialiseTier0GameUtilFunctions); diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index 2592cb3e..235bfe2e 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -10,6 +10,27 @@ #include #include + +// 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(stream.str(), false)); + spdlog::flush_on(spdlog::level::info); + } +} + long __stdcall ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) { static bool logged = false; @@ -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%Y-%m-%d %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%Y-%m-%d %H-%M-%S.txt"); - - // create logger - spdlog::default_logger()->sinks().push_back(std::make_shared(stream.str(), false)); } ConVar* Cvar_spewlog_enable; diff --git a/NorthstarDedicatedTest/logging.h b/NorthstarDedicatedTest/logging.h index 5a4522b4..da13e46f 100644 --- a/NorthstarDedicatedTest/logging.h +++ b/NorthstarDedicatedTest/logging.h @@ -1,5 +1,6 @@ #pragma once #include "context.h" +void CreateLogFiles(); void InitialiseLogging(); void InitialiseEngineSpewFuncHooks(HMODULE baseAddress); \ No newline at end of file -- cgit v1.2.3