diff --git a/gms/endpoint_state.cc b/gms/endpoint_state.cc index c9ecc244bf..feb9c377cc 100644 --- a/gms/endpoint_state.cc +++ b/gms/endpoint_state.cc @@ -35,12 +35,7 @@ const versioned_value* endpoint_state::get_application_state_ptr(application_sta } std::ostream& operator<<(std::ostream& os, const endpoint_state& x) { - fmt::print(os, "HeartBeatState = {}, AppStateMap =", x._heart_beat_state); - for (auto&entry : x._application_state) { - const application_state& state = entry.first; - const versioned_value& value = entry.second; - os << " { " << state << " : " << value << " } "; - } + fmt::print(os, "{}", x); return os; } @@ -67,3 +62,13 @@ future<> i_endpoint_state_change_subscriber::on_application_state_change(inet_ad } } + +auto fmt::formatter::format(const gms::endpoint_state& x, + fmt::format_context& ctx) const -> decltype(ctx.out()) { + auto out = ctx.out(); + out = fmt::format_to(out, "HeartBeatState = {}, AppStateMap =", x._heart_beat_state); + for (auto& [state, value] : x._application_state) { + out = fmt::format_to(out, " {{ {} : {} }} ", state, value); + } + return out; +} diff --git a/gms/endpoint_state.hh b/gms/endpoint_state.hh index dcfb0000bc..94ceb811a9 100644 --- a/gms/endpoint_state.hh +++ b/gms/endpoint_state.hh @@ -149,9 +149,11 @@ public: bool is_cql_ready() const noexcept; - friend std::ostream& operator<<(std::ostream& os, const endpoint_state& x); + friend fmt::formatter; }; +std::ostream& operator<<(std::ostream& os, const endpoint_state& x); + using endpoint_state_ptr = lw_shared_ptr; inline endpoint_state_ptr make_endpoint_state_ptr(const endpoint_state& eps) { @@ -174,3 +176,9 @@ using permit_id = utils::tagged_uuid; constexpr permit_id null_permit_id = permit_id::create_null_id(); } // gms + +template <> +struct fmt::formatter { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + auto format(const gms::endpoint_state&, fmt::format_context& ctx) const -> decltype(ctx.out()); +}; diff --git a/gms/gossip_digest_ack.cc b/gms/gossip_digest_ack.cc index 2df259315e..08c4232424 100644 --- a/gms/gossip_digest_ack.cc +++ b/gms/gossip_digest_ack.cc @@ -21,7 +21,7 @@ std::ostream& operator<<(std::ostream& os, const gossip_digest_ack& ack) { os << "} "; os << "endpoint_state:{"; for (auto& d : ack._map) { - os << "[" << d.first << "->" << d.second << "]"; + fmt::print(os, "[{}->{}]", d.first, d.second); } return os << "}"; } diff --git a/gms/gossip_digest_ack2.cc b/gms/gossip_digest_ack2.cc index f102ac7d86..50ba7f0438 100644 --- a/gms/gossip_digest_ack2.cc +++ b/gms/gossip_digest_ack2.cc @@ -16,7 +16,7 @@ namespace gms { std::ostream& operator<<(std::ostream& os, const gossip_digest_ack2& ack2) { os << "endpoint_state:{"; for (auto& d : ack2._map) { - os << "[" << d.first << "->" << d.second << "]"; + fmt::print(os, "[{}->{}]", d.first, d.second); } return os << "}"; }