13#include <fmt/format.h>
17#include <source_location>
19#include <unordered_map>
45 Logger(std::string name,
unsigned debug_level);
59 template <
typename... Args>
60 void info(
const char* fmt, Args&&... args)
65 fmt::styled(
"INFO ", fmt::fg(fmt::color::cornflower_blue)),
67 fmt::vformat(fmt, fmt::make_format_args(args...)));
76 template <
typename... Args>
81 "{} [{}] {}({}:{}) {}",
82 fmt::styled(
"DEBUG", fmt::fg(fmt::color::pale_violet_red)),
84 fmt::styled(data.
location.file_name(), fmt::fg(fmt::color::pale_turquoise)),
85 fmt::styled(data.
location.line(), fmt::fg(fmt::color::pale_turquoise)),
86 fmt::styled(data.
location.column(), fmt::fg(fmt::color::pale_turquoise)),
87 fmt::vformat(data.
message, fmt::make_format_args(args...)));
92 m_trace_starts[trace_name] = std::chrono::high_resolution_clock::now();
101 const auto time = std::chrono::high_resolution_clock::now();
102 const std::chrono::duration<double, std::milli> ms_double = time -
m_trace_starts[trace_name];
103 trace(
"{} took {:.3f}ms", trace_name, ms_double.count());
112 template <
typename... Args>
113 void trace(
const char* fmt, Args&&... args)
118 fmt::styled(
"TRACE", fmt::fg(fmt::color::golden_rod)),
120 fmt::vformat(fmt, fmt::make_format_args(args...)));
127 std::unordered_map<std::string, std::chrono::time_point<std::chrono::high_resolution_clock>>
m_trace_starts;
std::unordered_map< std::string, std::chrono::time_point< std::chrono::high_resolution_clock > > m_trace_starts
void info(const char *fmt, Args &&... args)
Write an info level log using fmtlib.
void trace(const char *fmt, Args &&... args)
Write a trace level log using fmtlib.
void debug(const Logger::MessageAndLocation data, Args &&... args)
Write a debug level log using fmtlib.
Logger(std::string name, unsigned debug_level)
Construct a new Logger object.
std::vector< std::string > m_active_traces
void traceStart(std::string &&trace_name)
unsigned debugLevel() const
std::source_location location
MessageAndLocation(T &&msg, const std::source_location loc=std::source_location::current())