Skip to content

Commit a55ac19

Browse files
committed
Replace fmt::localtime with localtime_r
fmt::localtime was deprecated in fmt 11.2.0 and removed in fmt 12.0.0. Replace with localtime_r, which is what fmt::localtime was implemented with internally. The new implementation maintains identical behavior by throwing a fmt::format_error exception when localtime_r() fails, matching the original fmt::localtime() behavior. See: https://github.com/fmtlib/fmt/releases/tag/12.0.0 Signed-off-by: Kefu Chai <tchaikov@gmail.com>
1 parent 6ce2bc0 commit a55ac19

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/logging.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ 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+
if (!localtime_r(&now, &tm_local)) {
33+
throw fmt::format_error("time_t value out of range");
34+
}
35+
*str += fmt::format("{:%F %T} ", tm_local);
3236

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

0 commit comments

Comments
 (0)