diff --git a/include/plog/Formatters/CsvFormatter.h b/include/plog/Formatters/CsvFormatter.h index 637c4167..f309c6d4 100644 --- a/include/plog/Formatters/CsvFormatter.h +++ b/include/plog/Formatters/CsvFormatter.h @@ -19,8 +19,9 @@ namespace plog util::localtime_s(&t, &record.getTime().time); util::nostringstream ss; - ss << t.tm_year + 1900 << PLOG_NSTR("/") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << PLOG_NSTR("/") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday << PLOG_NSTR(";"); - ss << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec << PLOG_NSTR(".") << std::setfill(PLOG_NSTR('0')) << std::setw(3) << record.getTime().millitm << PLOG_NSTR(";"); + util::nstring date, timeofday; + util::formatTime(&record.getTime(), &date, &timeofday); + ss << date << PLOG_NSTR(";") << timeofday << PLOG_NSTR(";"); ss << severityToString(record.getSeverity()) << PLOG_NSTR(";"); ss << record.getTid() << PLOG_NSTR(";"); ss << record.getObject() << PLOG_NSTR(";"); diff --git a/include/plog/Formatters/TxtFormatter.h b/include/plog/Formatters/TxtFormatter.h index df8ef240..37fc9636 100644 --- a/include/plog/Formatters/TxtFormatter.h +++ b/include/plog/Formatters/TxtFormatter.h @@ -15,12 +15,10 @@ namespace plog static util::nstring format(const Record& record) { - tm t; - util::localtime_s(&t, &record.getTime().time); - util::nostringstream ss; - ss << t.tm_year + 1900 << "-" << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << PLOG_NSTR("-") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday << PLOG_NSTR(" "); - ss << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec << PLOG_NSTR(".") << std::setfill(PLOG_NSTR('0')) << std::setw(3) << record.getTime().millitm << PLOG_NSTR(" "); + util::nstring date, timeofday; + util::formatTime(&record.getTime(), &date, &timeofday); + ss << date << PLOG_NSTR(" ") << timeofday << PLOG_NSTR(" "); ss << std::setfill(PLOG_NSTR(' ')) << std::setw(5) << std::left << severityToString(record.getSeverity()) << PLOG_NSTR(" "); ss << PLOG_NSTR("[") << record.getTid() << PLOG_NSTR("] "); ss << PLOG_NSTR("[") << record.getFunc() << PLOG_NSTR("@") << record.getLine() << PLOG_NSTR("] "); diff --git a/include/plog/Util.h b/include/plog/Util.h index 86b8ca31..08af4b03 100644 --- a/include/plog/Util.h +++ b/include/plog/Util.h @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,23 @@ namespace plog } #endif + inline void formatTime(const Time* time, nstring* date, nstring* timeofday) + { + struct tm t; + util::localtime_s(&t, &(time->time)); + + if (date != NULL) { + nostringstream ss; + ss << t.tm_year + 1900 << "-" << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << PLOG_NSTR("-") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday; + *date = ss.str(); + } + if (timeofday != NULL) { + nostringstream ss; + ss << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec << PLOG_NSTR(".") << std::setfill(PLOG_NSTR('0')) << std::setw(3) << time->millitm; + *timeofday = ss.str(); + } + } + inline unsigned int gettid() { #ifdef _WIN32