5#pragma clang diagnostic push
6#pragma clang diagnostic ignored "-Wshift-overflow"
8#pragma GCC diagnostic push
9#pragma GCC diagnostic ignored "-Wstringop-overflow"
12#include <fmt/format.h>
13#include <fmt/ranges.h>
15#pragma clang diagnostic pop
17#pragma GCC diagnostic pop
21#include <unordered_map>
88 static std::string
Header(std::string_view message,
int const width = 50);
91 template <
typename... VALUES>
92 void Trace(std::string_view message,
const VALUES... vals)
const {
Print(trace, message, vals...); }
94 template <
typename... VALUES>
95 void Debug(std::string_view message,
const VALUES... vals)
const {
Print(debug, message, vals...); }
97 template <
typename... VALUES>
98 void Info(std::string_view message,
const VALUES... vals)
const {
Print(info, message, vals...); }
100 template <
typename... VALUES>
101 void Warn(std::string_view message,
const VALUES... vals)
const {
Print(warn, message, vals...); }
103 template <
typename... VALUES>
104 void Error(std::string_view message,
const VALUES... vals)
const {
Print(error, message, vals...); }
111 template <
typename... VALUES>
112 void Print(
Level const lev, std::string_view message,
const VALUES... vals)
const
115 if(
auto it{m_level_names.find(lev)}; it != m_level_names.end()) {
116 std::function<std::string(std::string)> style = [](std::string s)
117 {
return fmt::format(
"[{}]", s); };
121 style = [](std::string s)
122 {
return fmt::format(
"[{}]", fmt::styled(s, fmt::emphasis::bold | fmt::fg(fmt::terminal_color::magenta))); };
125 style = [](std::string s)
126 {
return fmt::format(
"[{}]", fmt::styled(s, fmt::emphasis::bold | fmt::fg(fmt::terminal_color::red))); };
129 style = [](std::string s)
130 {
return fmt::format(
"[{}]", fmt::styled(s, fmt::emphasis::bold)); };
134 lev >= warn ? stderr : stdout,
135 fmt::runtime(fmt::format(
"{} {} {}\n", style(it->second), style(m_name), message)),
139 Warn(
"Logger::Print called with unknown log level '{}'; printing as error instead",
static_cast<int>(lev));
140 Error(message, vals...);
154 std::unordered_map<Level, std::string> m_level_names;
void Info(std::string_view message, const VALUES... vals) const
Printout a log message at the info level.
void Error(std::string_view message, const VALUES... vals) const
Printout a log message at the error level.
void EnableStyle()
Enable styled log printouts, with color and emphasis.
Logger(std::string_view name="log", Level const lev=DEFAULT_LEVEL, bool const enable_style=true)
void Trace(std::string_view message, const VALUES... vals) const
Printout a log message at the trace level.
void Debug(std::string_view message, const VALUES... vals) const
Printout a log message at the debug level.
void Print(Level const lev, std::string_view message, const VALUES... vals) const
static std::string Header(std::string_view message, int const width=50)
void SetLevel(std::string_view lev)
void Warn(std::string_view message, const VALUES... vals) const
Printout a log message at the warn level.
void SetLevel(Level const lev)
static Level const DEFAULT_LEVEL
The default log level.
void DisableStyle()
Disable styled log printout color and emphasis.
A named object with a Logger instance.
General, top-level namespace for algorithms and infrastructure. For algorithms and bindings,...