Add timestamp to log

This commit is contained in:
Grayson Riffe 2025-01-30 12:49:39 -06:00
parent 0c0c46e23d
commit ccfbc86f4f
2 changed files with 8 additions and 1 deletions

View File

@ -17,6 +17,9 @@ namespace nf {
SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str()); SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str());
#endif #endif
std::this_thread::sleep_for(std::chrono::seconds(1));
NFLog("Test!");
std::cin.get(); std::cin.get();
} }
} }

View File

@ -11,6 +11,8 @@ namespace nf::util {
static std::mutex s_logMutex; static std::mutex s_logMutex;
// Needed to enable Win32 virtual terminal processing // Needed to enable Win32 virtual terminal processing
static bool s_isLogInit = false; 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 // Mapping of type strings
static std::map<LogType, const char*> s_logTypesMap = { static std::map<LogType, const char*> s_logTypesMap = {
{LogType::Log, "\x1b[93mLog\x1b[0m"}, {LogType::Log, "\x1b[93mLog\x1b[0m"},
@ -32,7 +34,9 @@ namespace nf::util {
if (!s_isLogInit) if (!s_isLogInit)
initLog(); initLog();
std::cout << std::format("NF {}: {}\n", s_logTypesMap[type], msg); auto time = std::chrono::duration_cast<std::chrono::milliseconds>(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) { void log(const std::string& msg, LogType type) {