]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/formatter.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / 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
3
4 #include "formatter.h"
5
6 #include <fmt/format.h>
7 #if FMT_VERSION >= 60000
8 #include <fmt/chrono.h>
9 #else
10 #include <fmt/time.h>
11 #endif
12
13
14 template <>
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(); }
19
20 template <typename FormatContext>
21 auto format(const seastar::lowres_system_clock::time_point& t,
22 FormatContext& ctx) {
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);
29 }
30 };
31
32 template <>
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(); }
37
38 template <typename FormatContext>
39 auto format(const ceph::coarse_real_clock::time_point& t,
40 FormatContext& ctx) {
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);
47 }
48 };
49
50 namespace std {
51
52 ostream& operator<<(ostream& out,
53 const seastar::lowres_system_clock::time_point& t)
54 {
55 return out << fmt::format("{}", t);
56 }
57
58 ostream& operator<<(ostream& out,
59 const ceph::coarse_real_clock::time_point& t)
60 {
61 return out << fmt::format("{}", t);
62 }
63
64 }