From 60cc33a53cd401be92673c144eaa67555525933e Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:46:42 +0200 Subject: [PATCH] added time logging --- src/config/ConfigManager.cpp | 2 ++ src/debug/Log.cpp | 17 +++++++++++++++++ src/debug/Log.hpp | 1 + 3 files changed, 20 insertions(+) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 6ca263ee..8990e251 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -24,6 +24,7 @@ CConfigManager::CConfigManager() { configPaths.emplace_back(CONFIGPATH); Debug::disableLogs = &configValues["debug:disable_logs"].intValue; + Debug::disableTime = &configValues["debug:disable_time"].intValue; } void CConfigManager::setDefaultVars() { @@ -55,6 +56,7 @@ void CConfigManager::setDefaultVars() { configValues["debug:overlay"].intValue = 0; configValues["debug:damage_blink"].intValue = 0; configValues["debug:disable_logs"].intValue = 0; + configValues["debug:disable_time"].intValue = 1; configValues["decoration:rounding"].intValue = 1; configValues["decoration:blur"].intValue = 1; diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index 2fa4a127..59d2d239 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -41,6 +41,23 @@ void Debug::log(LogLevel level, const char* fmt, ...) { break; } + // print date and time to the ofs + if (disableTime && !*disableTime) { + auto timet = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + const auto MILLIS = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() % 1000; + + ofs << std::put_time(std::localtime(&timet), "[%H:%M:%S:"); + + if (MILLIS > 99) + ofs << MILLIS; + else if (MILLIS > 9) + ofs << "0" << MILLIS; + else + ofs << "00" << MILLIS; + + ofs << "] "; + } + char buf[LOGMESSAGESIZE] = ""; char* outputStr; int logLen; diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp index bde9b820..4001d996 100644 --- a/src/debug/Log.hpp +++ b/src/debug/Log.hpp @@ -18,4 +18,5 @@ namespace Debug { inline std::string logFile; inline int64_t* disableLogs = nullptr; + inline int64_t* disableTime = nullptr; }; \ No newline at end of file