TARAXA
Loading...
Searching...
No Matches
logger_formatters.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fmt/ostream.h>
4#include <fmt/ranges.h>
5
6#include <boost/beast/http/message_fwd.hpp>
8
9#include "common/types.hpp"
10
11// Logger fmt::formatters for custom types - not part of logger due to circular dependencies
12
13// Specialize fmt::formatter for std::atomic<T>
14template <typename T>
15struct fmt::formatter<std::atomic<T>> : fmt::formatter<T> {
16 template <typename FormatContext>
17 auto format(const std::atomic<T>& atomic_val, FormatContext& ctx) const {
18 return fmt::formatter<T>::format(atomic_val.load(std::memory_order_relaxed), ctx);
19 }
20};
21
22// Specialize fmt::formatter for taraxa::blk_hash_t
23template <>
24struct fmt::formatter<taraxa::blk_hash_t> : fmt::formatter<std::string> {
25 template <typename FormatContext>
26 auto format(const taraxa::blk_hash_t& val, FormatContext& ctx) const {
27 return fmt::format_to(ctx.out(), "{}", val.abridged());
28 }
29};
30
31// Specialize fmt::formatter for taraxa::addr_t
32template <>
33struct fmt::formatter<taraxa::addr_t> : fmt::formatter<std::string> {
34 template <typename FormatContext>
35 auto format(const taraxa::addr_t& val, FormatContext& ctx) const {
36 return fmt::format_to(ctx.out(), "{}", val.abridged());
37 }
38};
39
40// Specialize fmt::formatter for boost::beast::http::request
41template <class Body, class Fields>
42struct fmt::formatter<boost::beast::http::request<Body, Fields>> : fmt::ostream_formatter {};
std::string abridged() const
Definition FixedHash.h:167
Definition Log.h:104
std::hash for asio::adress
Definition FixedHash.h:483
Definition app.hpp:16
auto format(const std::atomic< T > &atomic_val, FormatContext &ctx) const
Definition logger_formatters.hpp:17
auto format(const taraxa::addr_t &val, FormatContext &ctx) const
Definition logger_formatters.hpp:35
auto format(const taraxa::blk_hash_t &val, FormatContext &ctx) const
Definition logger_formatters.hpp:26