Skip to content

Commit

Permalink
Lazy trace event formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 6, 2024
1 parent ed60faf commit 330856a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nano/lib/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,27 @@ class logger final
auto now = std::chrono::high_resolution_clock::now ();

// TODO: Improve code indentation config
auto logger = get_logger (type, detail);
auto & logger = get_logger (type, detail);
logger.trace ("{}",
nano::streamed_args (global_tracing_config,
nano::log::arg{ "event", to_string (std::make_pair (type, detail)) },
nano::log::arg{ "event", event_formatter{ type, detail } },
nano::log::arg{ "time", nano::log::microseconds (now) },
std::forward<Args> (args)...));
}
}

private:
struct event_formatter final
{
nano::log::type type;
nano::log::detail detail;

friend std::ostream & operator<< (std::ostream & os, event_formatter const & self)
{
return os << to_string (self.type) << "::" << to_string (self.detail);
}
};

private:
const std::string identifier;

Expand Down

0 comments on commit 330856a

Please sign in to comment.