From d403a327669e9ba8bacbef3cb4017d84a281f02d Mon Sep 17 00:00:00 2001 From: okaestne Date: Sun, 4 Sep 2022 19:56:10 +0200 Subject: [PATCH] fix time format string for use with MinGW; use std::chrono::system_clock --- Log.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Log.cpp b/Log.cpp index e8b7b64..3328e4e 100644 --- a/Log.cpp +++ b/Log.cpp @@ -161,11 +161,16 @@ void Entry::addMetadataHeader() { static const char* LevelTag[] = {"", "[FATAL] ", "[ERROR] ", "[WARN ] ", "[NOTE ] ", "[INFO ] ", "[DEBUG] ", "[TRACE] "}; - // get current date/time - std::time_t now = std::time(NULL); - // datetime - ss << "[" << std::put_time(std::localtime(&now), "%F %T") << "]"; + using namespace std::chrono; + auto now = system_clock::to_time_t(system_clock::now()); + auto tm = *std::localtime(&now); + + // MinGW doesn't support the ISO8601 formatting characters like "%F" and "%T" + // ref: https://sourceforge.net/p/mingw-w64/bugs/793/ + // Therefore, use a more verbose time string + ss << "[" << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") << "]"; + // log level ss << LevelTag[lvl]; }