From 70fbe2b88495d7239a972a4fd209ee68477eb2fa Mon Sep 17 00:00:00 2001 From: p0358 Date: Mon, 19 Sep 2022 01:56:12 +0200 Subject: Display error if logs path isn't writeable (#274) --- NorthstarDLL/logging.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/NorthstarDLL/logging.cpp b/NorthstarDLL/logging.cpp index 38d58fa0..4d277767 100644 --- a/NorthstarDLL/logging.cpp +++ b/NorthstarDLL/logging.cpp @@ -19,14 +19,23 @@ void CreateLogFiles() } 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, (GetNorthstarPrefix() + "/logs/nslog%Y-%m-%d %H-%M-%S.txt").c_str()); - spdlog::default_logger()->sinks().push_back(std::make_shared(stream.str(), false)); - spdlog::flush_on(spdlog::level::info); + try + { + // 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, (GetNorthstarPrefix() + "/logs/nslog%Y-%m-%d %H-%M-%S.txt").c_str()); + spdlog::default_logger()->sinks().push_back(std::make_shared(stream.str(), false)); + spdlog::flush_on(spdlog::level::info); + } + catch (...) + { + spdlog::error("Failed creating log file"); + MessageBoxA( + 0, "Failed creating log file! Make sure the profile directory is writable.", "Northstar Warning", MB_ICONWARNING | MB_OK); + } } } -- cgit v1.2.3