fix time format string for use with MinGW; use std::chrono::system_clock

This commit is contained in:
Oliver 2022-09-04 19:56:10 +02:00
parent 21471c13c0
commit d403a32766
Signed by untrusted user: okaestne
GPG Key ID: 06A81B143EA9588F
1 changed files with 9 additions and 4 deletions

13
Log.cpp
View File

@ -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];
}