Replace fmt::localtime() with localtime_r() to fix build failure with
fmt 11.2.0, where fmt::localtime() was deprecated in favor of std::localtime.
The deprecated function causes build errors when treating warnings as errors:
```
In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/LogEntry.cc:7:
In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/LogEntry.h:22:
/home/jenkins-build/build/workspace/ceph-pull-requests/src/include/utime_fmt.h:37:25: error: 'localtime' is deprecated [-Werror,-Wdeprecated-declarations]
37 | auto aslocal = fmt::localtime(utime.sec());
| ^
/home/jenkins-build/build/workspace/ceph-pull-requests/src/fmt/include/fmt/chrono.h:538:1: note: 'localtime' has been explicitly marked deprecated here
538 | FMT_DEPRECATED inline auto localtime(std::time_t time) -> std::tm {
| ^
/home/jenkins-build/build/workspace/ceph-pull-requests/src/fmt/include/fmt/base.h:207:28: note: expanded from macro 'FMT_DEPRECATED'
207 | # define FMT_DEPRECATED [[deprecated]]
| ^
1 error generated.
```
Using localtime_r() provides thread-safe behavior with user-provided
buffers instead of static storage, addressing the deprecation while
maintaining functionality.
See: https://github.com/fmtlib/fmt/releases/tag/11.2.0
This should address the build failure, and should prepare us for
switching to fmt 11.2.0, which in turn includes a bug fix preventing us
from building with Clang 20.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
// this looks like an absolute time.
// conform to http://en.wikipedia.org/wiki/ISO_8601
// (unless short_format is set)
- auto aslocal = fmt::localtime(utime.sec());
+ std::time_t time = utime.sec();
+ std::tm aslocal;
+ if (!localtime_r(&time, &aslocal)) {
+ throw fmt::format_error("time_t value out of range");
+ }
if (short_format) {
return fmt::format_to(ctx.out(), "{:%FT%T}.{:03}", aslocal,
utime.usec() / 1000);