-
Notifications
You must be signed in to change notification settings - Fork 0
Logger
Summary of logging features.
The core API is in logger/log.hpp
, which contains free functions to error, warning, info, and debug log messages. General usage involves including this header and calling the relevant log functions. All functions can be called from any thread at any time.
The internals of the logger are controlled by an RAII logger::Instance
that the user is expected to own for as long as they need logging (in most cases at the top of main
). Its constructor takes a path to create a log file at, and the log configuration to use (described below). It also allows overwriting the configuration at runtime, and adding custom sinks.
A logger::Target
describes the "channels" to route logs through:
-
console_v
: stdout / stderr. -
file_v
: to the log file created byInstance
. -
sinks_v
: to custom sinks connected (if any). -
all_v
: everything.
logger::Config
exposes various knobs and switches:
-
format
: A format string providing the layout of formatted log messages. -
maxLevel
: MaximumLevel
to log. -
categoryMaxLevels
: MaximumLevel
override per category (by default the same asmaxLevel
). -
levelTargets
: destinations for eachLevel
(by default all). -
timestamp
: whether to print local / UTC timestamps.
Since the logging API is thread-safe, there is no way to obtain a reference to the currently active Config
, it can be only be copied and swapped.
logger::Sink
is a customization point for receiving formatted log messages. Inherit from it, override handle(std::string_view formatted, Context const& context)
, and add an instance of your type via Instance::addSink
, to receive callbacks on every logged message.
logger::Context
contains all the relevant metadata for a particular log message, passed in Sink
callbacks. It can be useful to mirror log messages on a Dear ImGui window, for example.