8#include <source_location>
22 enum class Level {
Error, Warn, Info, Verbose, Debug, Trace };
31 explicit operator bool()
const {
return ostream_; }
41 max_level_ = max_level;
47 template<
class... Args>
50 requires std::convertible_to<const S&, std::string_view>
51 consteval FmtLoc(
const S&
fmt, std::source_location
loc = std::source_location::current())
55 std::format_string<Args...>
fmt;
56 std::source_location
loc;
61 template<
class... Args>
67 template<
class... Args>
68 void log(
Level level,
Loc loc, std::format_string<Args...> fmt, Args&&... args)
const {
69 if (ostream_ &&
level <= max_level_) emit(
level, loc, fmt, std::forward<Args>(args)...);
73 template<
class... Args>
74 void log(
Level level, std::source_location where, std::format_string<Args...> fmt, Args&&... args)
const {
75 if (ostream_ &&
level <= max_level_)
76 emit(
level, std::format(
"{}:{}", where.file_name(), where.line()), fmt, std::forward<Args>(args)...);
80 template<
class... Args>
89 template<
class... Args>
93 template<
class... Args>
97 template<
class... Args>
101 template<
class... Args>
111 template<
class... Args>
115 template<
class... Args>
120 template<
class... Args>
122 template<
class... Args>
163 template<
class W,
class... Args>
164 void emit(Level
level,
const W& where, std::format_string<Args...> fmt, Args&&... args)
const {
167 std::println(
ostream(), fmt, std::forward<Args>(args)...);
171 std::ostream* ostream_ =
nullptr;
Collects diagnostics and hands each to the Diag that lays it out.
Facility to log what you are doing.
Log & set(std::ostream *ostream)
void e(Fmt< Args... > fmt, Args &&... args) const
void log(Level level, std::source_location where, std::format_string< Args... > fmt, Args &&... args) const
A std::source_location is no Loc: it points into your source, which has no fe::Src.
FmtLoc< std::type_identity_t< Args >... > Fmt
Puts the Args of a Log::FmtLoc parameter into a non-deduced context, so that they are deduced from th...
static term::FG level2color(Level level)
void d(Fmt< Args... > fmt, Args &&... args) const
static char level2acro(Level level)
void t(Fmt< Args... > fmt, Args &&... args) const
Log & set(Level max_level)
void w(Fmt< Args... > fmt, Args &&... args) const
void v(Fmt< Args... > fmt, Args &&... args) const
void log(Level level, Fmt< Args... > fmt, Args &&... args) const
Points at the call site.
std::ostream & ostream() const
void log(Level level, Loc loc, std::format_string< Args... > fmt, Args &&... args) const
void i(Fmt< Args... > fmt, Args &&... args) const
FG
Foreground colors that can be streamed into an std::ostream.
void breakpoint()
Raise a breakpoint in the debugger.
Location within a Src: the half-open byte range [Loc::begin, Loc::end).
A std::format_string that remembers where it was written.
consteval FmtLoc(const S &fmt, std::source_location loc=std::source_location::current())
std::format_string< Args... > fmt