diff --git a/nano/lib/logging.hpp b/nano/lib/logging.hpp index 4aa6178e10..4f219a1745 100644 --- a/nano/lib/logging.hpp +++ b/nano/lib/logging.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -159,7 +160,7 @@ class logger final if constexpr (is_tracing_enabled ()) { auto logger = get_logger (type, detail); - logger.trace ("<{}> {}", to_string (detail), nano::object_stream_formatter{ global_tracing_config, std::forward (args)... }); + logger.trace ("{}", nano::object_streamed_args (global_tracing_config, nano::log::arg{ "event", detail }, std::forward (args)...)); } } diff --git a/nano/lib/object_stream.hpp b/nano/lib/object_stream.hpp index dba0084f8c..69a2626735 100644 --- a/nano/lib/object_stream.hpp +++ b/nano/lib/object_stream.hpp @@ -363,38 +363,6 @@ inline void nano::root_object_stream::write_range (Container const & container) }); } -/** - * Wraps {name,value} args and provides a `<< (std::ostream &, ...)` operator that writes the arguments to the stream in a lazy manner. - */ -template -struct object_stream_formatter -{ - object_stream_config const & config; - std::tuple args; - - explicit object_stream_formatter (object_stream_config const & config, Args &&... args) : - config{ config }, - args{ std::forward (args)... } - { - } - - friend std::ostream & operator<< (std::ostream & os, object_stream_formatter const & self) - { - nano::object_stream obs{ os, self.config }; - std::apply ([&obs] (auto &&... args) { - ((obs.write (args.name, args.value)), ...); - }, - self.args); - return os; - } - - // Needed for fmt formatting, uses the ostream operator under the hood - friend auto format_as (object_stream_formatter const & val) - { - return fmt::streamed (val); - } -}; - /* * Writers */ diff --git a/nano/lib/object_stream_ostream.hpp b/nano/lib/object_stream_ostream.hpp index da42d81d65..4fbd79e642 100644 --- a/nano/lib/object_stream_ostream.hpp +++ b/nano/lib/object_stream_ostream.hpp @@ -40,4 +40,42 @@ auto format_as (Value const & value) { return fmt::streamed (value); } + +/** + * Wraps {name,value} args and provides `<<(std::ostream &, ...)` and fmt format operator that writes the arguments to the stream in a lazy manner. + */ +template +struct object_stream_args_formatter +{ + nano::object_stream_config const & config; + std::tuple args; + + explicit object_stream_args_formatter (nano::object_stream_config const & config, Args &&... args) : + config{ config }, + args{ std::forward (args)... } + { + } + + friend std::ostream & operator<< (std::ostream & os, object_stream_args_formatter const & self) + { + nano::object_stream obs{ os, self.config }; + std::apply ([&obs] (auto &&... args) { + ((obs.write (args.name, args.value)), ...); + }, + self.args); + return os; + } + + // Needed for fmt formatting, uses the ostream operator under the hood + friend auto format_as (object_stream_args_formatter const & val) + { + return fmt::streamed (val); + } +}; + +template +auto object_streamed_args (nano::object_stream_config const & config, Args &&... args) +{ + return object_stream_args_formatter{ config, std::forward (args)... }; +} } \ No newline at end of file