Skip to content

Commit 26a5fc0

Browse files
committed
CsvFormatter.h also use util::formatTime
1 parent 11a122f commit 26a5fc0

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

include/plog/Formatters/CsvFormatter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ namespace plog
1919
util::localtime_s(&t, &record.getTime().time);
2020

2121
util::nostringstream ss;
22-
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(";");
23-
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(";");
22+
util::nstring date, timeofday;
23+
util::formatTime(&record.getTime(), &date, &timeofday);
24+
ss << date << PLOG_NSTR(";") << timeofday << PLOG_NSTR(";");
2425
ss << severityToString(record.getSeverity()) << PLOG_NSTR(";");
2526
ss << record.getTid() << PLOG_NSTR(";");
2627
ss << record.getObject() << PLOG_NSTR(";");

include/plog/Formatters/TxtFormatter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ namespace plog
1616
static util::nstring format(const Record& record)
1717
{
1818
util::nostringstream ss;
19-
ss << util::formatTime(&record.getTime());
19+
util::nstring date, timeofday;
20+
util::formatTime(&record.getTime(), &date, &timeofday);
21+
ss << date << PLOG_NSTR(" ") << timeofday << PLOG_NSTR(" ");
2022
ss << std::setfill(PLOG_NSTR(' ')) << std::setw(5) << std::left << severityToString(record.getSeverity()) << PLOG_NSTR(" ");
2123
ss << PLOG_NSTR("[") << record.getTid() << PLOG_NSTR("] ");
2224
ss << PLOG_NSTR("[") << record.getFunc() << PLOG_NSTR("@") << record.getLine() << PLOG_NSTR("] ");

include/plog/Util.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,21 @@ namespace plog
9191
}
9292
#endif
9393

94-
inline util::nstring formatTime(const Time* time)
94+
inline void formatTime(const Time* time, nstring* date, nstring* timeofday)
9595
{
9696
struct tm t;
9797
util::localtime_s(&t, &(time->time));
9898

99-
nostringstream ss;
100-
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(" ");
101-
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 << PLOG_NSTR(" ");
102-
return ss.str();
99+
if (date != NULL) {
100+
nostringstream ss;
101+
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;
102+
*date = ss.str();
103+
}
104+
if (timeofday != NULL) {
105+
nostringstream ss;
106+
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;
107+
*timeofday = ss.str();
108+
}
103109
}
104110

105111
inline unsigned int gettid()

0 commit comments

Comments
 (0)