FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches
fe::Log Class Reference

Facility to log what you are doing. More...

#include <fe/log.h>

Classes

struct  FmtLoc
 A cite_string that remembers where it was written. More...

Public Types

enum class  Level {
  Error ,
  Warn ,
  Info ,
  Verbose ,
  Debug ,
  Trace ,
  E = Error ,
  W = Warn ,
  I = Info ,
  V = Verbose ,
  D = Debug ,
  T = Trace
}
template<class... Args>
using Fmt = FmtLoc<std::type_identity_t<Args>...>
 Puts the Args of a Log::FmtLoc parameter into a non-deduced context, so that they are deduced from the trailing arguments and the format string keeps capturing its call site.

Public Member Functions

Getters
Level level () const
std::ostream & ostream () const
 operator bool () const
 Checks if Log::ostream_ is set.
Setters
Logset (std::ostream *ostream)
Logset (Level max_level)
Log

Output fmt to Log::ostream; does nothing if Log::ostream is nullptr.

template<class... Args>
void log (Level level, Loc loc, cite_string< Args... > fmt, Args &&... args) const
template<class... Args>
void log (Level level, std::source_location where, cite_string< Args... > fmt, Args &&... args) const
 A std::source_location is no Loc: it points into your source, which has no fe::Src.
template<class... Args>
void log (Level level, Fmt< Args... > fmt, Args &&... args) const
 Points at the call site.
Level Shorthands

Log at a fixed Level, pointing at the call site.

template<class... Args>
void e (Fmt< Args... > fmt, Args &&... args) const
template<class... Args>
void w (Fmt< Args... > fmt, Args &&... args) const
template<class... Args>
void i (Fmt< Args... > fmt, Args &&... args) const
template<class... Args>
void v (Fmt< Args... > fmt, Args &&... args) const
Debug Shorthands

Vaporize to nothingness in Release build; the arguments are still evaluated.

template<class... Args>
void d (Fmt< Args... > fmt, Args &&... args) const
template<class... Args>
void t (Fmt< Args... > fmt, Args &&... args) const

Static Public Member Functions

Conversions
static char level2acro (Level level)
static term::FG level2color (Level level)

Public Attributes

Breakpoints
bool break_on_error = false
bool break_on_warn = false

Detailed Description

Facility to log what you are doing.

Definition at line 21 of file log.h.

Member Typedef Documentation

◆ Fmt

template<class... Args>
using fe::Log::Fmt = FmtLoc<std::type_identity_t<Args>...>

Puts the Args of a Log::FmtLoc parameter into a non-deduced context, so that they are deduced from the trailing arguments and the format string keeps capturing its call site.

Definition at line 76 of file log.h.

Member Enumeration Documentation

◆ Level

enum class fe::Log::Level
strong
Enumerator
Error 
Warn 
Info 
Verbose 
Debug 
Trace 

Definition at line 23 of file log.h.

Member Function Documentation

◆ d()

template<class... Args>
void fe::Log::d ( Fmt< Args... > fmt,
Args &&... args ) const
inline

Definition at line 116 of file log.h.

References Debug, and log().

◆ e()

template<class... Args>
void fe::Log::e ( Fmt< Args... > fmt,
Args &&... args ) const
inline

Definition at line 104 of file log.h.

References E, and log().

◆ i()

template<class... Args>
void fe::Log::i ( Fmt< Args... > fmt,
Args &&... args ) const
inline

Definition at line 106 of file log.h.

References I, and log().

◆ level()

Level fe::Log::level ( ) const
inline

Definition at line 40 of file log.h.

Referenced by level2acro(), level2color(), log(), log(), and log().

◆ level2acro()

char fe::Log::level2acro ( Level level)
static

References level().

Referenced by level2color().

◆ level2color()

◆ log() [1/3]

template<class... Args>
void fe::Log::log ( Level level,
Fmt< Args... > fmt,
Args &&... args ) const
inline

Points at the call site.

Definition at line 95 of file log.h.

References fe::Log::FmtLoc< Args >::fmt, level(), fe::Log::FmtLoc< Args >::loc, and log().

◆ log() [2/3]

template<class... Args>
void fe::Log::log ( Level level,
Loc loc,
cite_string< Args... > fmt,
Args &&... args ) const
inline

Definition at line 82 of file log.h.

References level().

Referenced by d(), e(), i(), log(), t(), v(), and w().

◆ log() [3/3]

template<class... Args>
void fe::Log::log ( Level level,
std::source_location where,
cite_string< Args... > fmt,
Args &&... args ) const
inline

A std::source_location is no Loc: it points into your source, which has no fe::Src.

Definition at line 88 of file log.h.

References level().

◆ operator bool()

fe::Log::operator bool ( ) const
inlineexplicit

Checks if Log::ostream_ is set.

Definition at line 45 of file log.h.

◆ ostream()

std::ostream & fe::Log::ostream ( ) const
inline

Definition at line 41 of file log.h.

Referenced by level2color(), and set().

◆ set() [1/2]

Log & fe::Log::set ( Level max_level)
inline

Definition at line 54 of file log.h.

◆ set() [2/2]

Log & fe::Log::set ( std::ostream * ostream)
inline

Definition at line 50 of file log.h.

References ostream().

◆ t()

template<class... Args>
void fe::Log::t ( Fmt< Args... > fmt,
Args &&... args ) const
inline

Definition at line 117 of file log.h.

References log(), and Trace.

◆ v()

template<class... Args>
void fe::Log::v ( Fmt< Args... > fmt,
Args &&... args ) const
inline

Definition at line 107 of file log.h.

References log(), and V.

◆ w()

template<class... Args>
void fe::Log::w ( Fmt< Args... > fmt,
Args &&... args ) const
inline

Definition at line 105 of file log.h.

References log(), and W.

Member Data Documentation

◆ break_on_error

bool fe::Log::break_on_error = false

Definition at line 127 of file log.h.

Referenced by level2color().

◆ break_on_warn

bool fe::Log::break_on_warn = false

Definition at line 128 of file log.h.

Referenced by level2color().


The documentation for this class was generated from the following file: