Skip to content

Commit 6c96199

Browse files
authored
Merge pull request #2457 from tchaikov/fix-fmt12-localtime
Replace fmt::localtime with localtime_r
2 parents 6ce2bc0 + dec2937 commit 6c96199

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/logging.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ void logger_t::generate_common_prefix(std::string *str,
2727
fmt::text_style const &ts,
2828
char const *prefix) const
2929
{
30-
*str += fmt::format("{:%Y-%m-%d %H:%M:%S} ",
31-
fmt::localtime(std::time(nullptr)));
30+
auto const now = std::time(nullptr);
31+
std::tm tm_local{};
32+
#ifdef _MSC_VER
33+
if (localtime_s(&tm_local, &now) != 0) {
34+
throw fmt::format_error("time_t value out of range");
35+
}
36+
#else
37+
if (!localtime_r(&now, &tm_local)) {
38+
throw fmt::format_error("time_t value out of range");
39+
}
40+
#endif
41+
*str += fmt::format("{:%F %T} ", tm_local);
3242

3343
if (m_current_level == log_level::debug) {
3444
*str += fmt::format(ts, "[{:02d}] ", this_thread_num);

0 commit comments

Comments
 (0)