]>
git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/formatter.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include <fmt/format.h>
7 #if FMT_VERSION >= 60000
8 #include <fmt/chrono.h>
15 struct fmt::formatter
<seastar::lowres_system_clock::time_point
> {
16 // ignore the format string
17 template <typename ParseContext
>
18 constexpr auto parse(ParseContext
&ctx
) { return ctx
.begin(); }
20 template <typename FormatContext
>
21 auto format(const seastar::lowres_system_clock::time_point
& t
,
23 std::time_t tt
= std::chrono::duration_cast
<std::chrono::seconds
>(
24 t
.time_since_epoch()).count();
25 auto milliseconds
= (t
.time_since_epoch() %
26 std::chrono::seconds(1)).count();
27 return fmt::format_to(ctx
.out(), "{:%Y-%m-%d %H:%M:%S} {:03d}",
28 fmt::localtime(tt
), milliseconds
);
33 struct fmt::formatter
<ceph::coarse_real_clock::time_point
> {
34 // ignore the format string
35 template <typename ParseContext
>
36 constexpr auto parse(ParseContext
&ctx
) { return ctx
.begin(); }
38 template <typename FormatContext
>
39 auto format(const ceph::coarse_real_clock::time_point
& t
,
41 std::time_t tt
= std::chrono::duration_cast
<std::chrono::seconds
>(
42 t
.time_since_epoch()).count();
43 auto milliseconds
= (t
.time_since_epoch() %
44 std::chrono::seconds(1)).count();
45 return fmt::format_to(ctx
.out(), "{:%Y-%m-%d %H:%M:%S} {:03d}",
46 fmt::localtime(tt
), milliseconds
);
52 ostream
& operator<<(ostream
& out
,
53 const seastar::lowres_system_clock::time_point
& t
)
55 return out
<< fmt::format("{}", t
);
58 ostream
& operator<<(ostream
& out
,
59 const ceph::coarse_real_clock::time_point
& t
)
61 return out
<< fmt::format("{}", t
);