From b03d46370ff0d824948befa1099e87c2fb36879c Mon Sep 17 00:00:00 2001 From: XargonWan Date: Mon, 2 Dec 2024 11:33:26 +0900 Subject: [PATCH] LOGGER: added milliseconds --- es-core/src/Log.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/es-core/src/Log.cpp b/es-core/src/Log.cpp index c5e67607c..ab920e576 100644 --- a/es-core/src/Log.cpp +++ b/es-core/src/Log.cpp @@ -103,10 +103,25 @@ std::ostringstream& Log::get(LogLevel level) std::string levelUpper = mLogLevelMap[level]; std::transform(levelUpper.begin(), levelUpper.end(), levelUpper.begin(), ::toupper); + // Get current time with milliseconds + auto now = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; + auto time = std::chrono::system_clock::to_time_t(now); + tm = *std::localtime(&time); + mOutStringStream << "[" << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") + << "." << std::setfill('0') << std::setw(3) << ms.count() // Add milliseconds << "] [" << levelUpper << "] [ES-DE] "; #else - mOutStringStream << std::put_time(&tm, "%b %d %H:%M:%S ") << mLogLevelMap[level] + // Get current time with milliseconds + auto now = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; + auto time = std::chrono::system_clock::to_time_t(now); + tm = *std::localtime(&time); + + mOutStringStream << "[" << std::put_time(&tm, "%b %d %H:%M:%S") + << "." << std::setfill('0') << std::setw(3) << ms.count() // Add milliseconds + << "] " << mLogLevelMap[level] << (level == LogLevel::LogInfo || level == LogLevel::LogWarning ? ": " : ": "); #endif