From ccfbc86f4f3893792f83a994af6b9e1659885fdd Mon Sep 17 00:00:00 2001 From: Grayson Riffe Date: Thu, 30 Jan 2025 12:49:39 -0600 Subject: [PATCH] Add timestamp to log --- NothinFancy/src/Engine.cpp | 3 +++ NothinFancy/src/util/log.cpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NothinFancy/src/Engine.cpp b/NothinFancy/src/Engine.cpp index 6cc79d2..cb123f6 100644 --- a/NothinFancy/src/Engine.cpp +++ b/NothinFancy/src/Engine.cpp @@ -17,6 +17,9 @@ namespace nf { SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str()); #endif + std::this_thread::sleep_for(std::chrono::seconds(1)); + NFLog("Test!"); + std::cin.get(); } } diff --git a/NothinFancy/src/util/log.cpp b/NothinFancy/src/util/log.cpp index 7f0a140..b1184e0 100644 --- a/NothinFancy/src/util/log.cpp +++ b/NothinFancy/src/util/log.cpp @@ -11,6 +11,8 @@ namespace nf::util { static std::mutex s_logMutex; // Needed to enable Win32 virtual terminal processing static bool s_isLogInit = false; + // When application was started + static std::chrono::time_point s_initTime = std::chrono::high_resolution_clock::now(); // Mapping of type strings static std::map s_logTypesMap = { {LogType::Log, "\x1b[93mLog\x1b[0m"}, @@ -32,7 +34,9 @@ namespace nf::util { if (!s_isLogInit) initLog(); - std::cout << std::format("NF {}: {}\n", s_logTypesMap[type], msg); + auto time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - s_initTime); + + std::cout << std::format("[{:9.3f}] NF {}: {}\n", time.count() * 1e-3, s_logTypesMap[type], msg); } void log(const std::string& msg, LogType type) {