iterative-solver 0.0
 
Loading...
Searching...
No Matches
molpro::linalg::itsolv::Logger Class Reference

Logger class implementation. Provides (customizable) logging functionalities. More...

#include <Logger.h>

Detailed Description

Logger class implementation. Provides (customizable) logging functionalities.

See Logger.h for an overview of how to observe logged events.

Public Types

using Sink = std::function< void(const log::Record &)>
 
using SinkId = std::size_t
 

Public Member Functions

 Logger (log::Severity min_severity=log::Severity::Normal, log::Verbosity verbosity=log::Verbosity::Info, bool enable_data_dumps=false)
 
virtual ~Logger ()=default
 
SinkId add_sink (Sink sink, log::Filter filter={})
 Registers a sink receiving all events that pass the given filter.
 
template<log::event_context Ctx, typename F >
requires std::invocable<F &, const log::Record &, const typename Ctx::Payload &>
SinkId on (F &&f)
 Registers f(const log::Record &, const Ctx::Payload &) to be called for every event of context Ctx.
 
void remove_sink (SinkId id)
 Removes a previously registered sink.
 
template<log::event_context Ctx, typename MakePayload >
requires std::invocable<MakePayload &>
void emit (log::Severity severity, log::Verbosity verbosity, std::string_view message, MakePayload &&make) const
 Emits an event of context Ctx.
 
template<log::event_context Ctx>
bool is_wanted (log::Severity severity, log::Verbosity verbosity) const
 
template<log::event_context Ctx>
requires std::default_initializable<typename Ctx::Payload>
void emit (log::Severity severity, log::Verbosity verbosity, std::string_view message) const
 Emits an event of a context whose payload is default-constructible (usually empty)
 
template<typename... Ts>
void msg (log::Severity severity, log::Verbosity verbosity, std::string_view message, const Ts &...args) const
 Logs a free-text message (context log::Generic). The arguments are stringified and appended.
 
template<typename... Ts>
void trace (std::string_view message, const Ts &...args) const
 
template<typename... Ts>
void debug (std::string_view message, const Ts &...args) const
 
template<typename... Ts>
void info (std::string_view message, const Ts &...args) const
 
template<typename... Ts>
void warn (std::string_view message, const Ts &...args) const
 
template<typename... Ts>
void error (std::string_view message, const Ts &...args) const
 
template<typename... Ts>
void fatal (std::string_view message, const Ts &...args) const
 
template<std::size_t precision = log::default_precision, typename T >
void data_dump (std::string_view what, const T &data) const
 Dumps data (context log::DataDump<T>, verbosity Trace). Nothing is copied.
 
log::Severity min_severity () const
 
void set_min_severity (log::Severity severity)
 
log::Verbosity verbosity () const
 
void set_verbosity (log::Verbosity verbosity)
 
bool data_dumps_enabled () const
 
void enable_data_dumps (bool enable)
 
bool default_output () const
 
void set_default_output (bool enable)
 Switches the built-in text output (default_message_handler()) on or off.
 

Protected Member Functions

virtual void default_message_handler (std::string_view ctx, log::Severity severity, log::Verbosity verbosity, std::string_view msg) const
 Built-in text output. Receives every event passing the logger's thresholds and data-dump flag.
 

Member Typedef Documentation

◆ Sink

◆ SinkId

Constructor & Destructor Documentation

◆ Logger()

molpro::linalg::itsolv::Logger::Logger ( log::Severity  min_severity = log::Severity::Normal,
log::Verbosity  verbosity = log::Verbosity::Info,
bool  enable_data_dumps = false 
)
inline

◆ ~Logger()

virtual molpro::linalg::itsolv::Logger::~Logger ( )
virtualdefault

Member Function Documentation

◆ add_sink()

SinkId molpro::linalg::itsolv::Logger::add_sink ( Sink  sink,
log::Filter  filter = {} 
)
inline

Registers a sink receiving all events that pass the given filter.

Returns
An id that can be passed to remove_sink()

◆ data_dump()

template<std::size_t precision = log::default_precision, typename T >
void molpro::linalg::itsolv::Logger::data_dump ( std::string_view  what,
const T &  data 
) const
inline

Dumps data (context log::DataDump<T>, verbosity Trace). Nothing is copied.

◆ data_dumps_enabled()

bool molpro::linalg::itsolv::Logger::data_dumps_enabled ( ) const
inline

◆ debug()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::debug ( std::string_view  message,
const Ts &...  args 
) const
inline

◆ default_message_handler()

virtual void molpro::linalg::itsolv::Logger::default_message_handler ( std::string_view  ctx,
log::Severity  severity,
log::Verbosity  verbosity,
std::string_view  msg 
) const
inlineprotectedvirtual

Built-in text output. Receives every event passing the logger's thresholds and data-dump flag.

Override this to redirect the text output.

◆ default_output()

bool molpro::linalg::itsolv::Logger::default_output ( ) const
inline

◆ emit() [1/2]

template<log::event_context Ctx>
requires std::default_initializable<typename Ctx::Payload>
void molpro::linalg::itsolv::Logger::emit ( log::Severity  severity,
log::Verbosity  verbosity,
std::string_view  message 
) const
inline

Emits an event of a context whose payload is default-constructible (usually empty)

◆ emit() [2/2]

template<log::event_context Ctx, typename MakePayload >
requires std::invocable<MakePayload &>
void molpro::linalg::itsolv::Logger::emit ( log::Severity  severity,
log::Verbosity  verbosity,
std::string_view  message,
MakePayload &&  make 
) const
inline

Emits an event of context Ctx.

Parameters
makeCallable creating the payload. It is only invoked if some sink is interested in the event.

◆ enable_data_dumps()

void molpro::linalg::itsolv::Logger::enable_data_dumps ( bool  enable)
inline

◆ error()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::error ( std::string_view  message,
const Ts &...  args 
) const
inline

◆ fatal()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::fatal ( std::string_view  message,
const Ts &...  args 
) const
inline

◆ info()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::info ( std::string_view  message,
const Ts &...  args 
) const
inline

◆ is_wanted()

template<log::event_context Ctx>
bool molpro::linalg::itsolv::Logger::is_wanted ( log::Severity  severity,
log::Verbosity  verbosity 
) const
inline
Returns
Whether an event of context Ctx with the given severity and verbosity would reach any sink. Emitters can use this to skip preparing data that only goes into the payload.

◆ min_severity()

log::Severity molpro::linalg::itsolv::Logger::min_severity ( ) const
inline

◆ msg()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::msg ( log::Severity  severity,
log::Verbosity  verbosity,
std::string_view  message,
const Ts &...  args 
) const
inline

Logs a free-text message (context log::Generic). The arguments are stringified and appended.

◆ on()

template<log::event_context Ctx, typename F >
requires std::invocable<F &, const log::Record &, const typename Ctx::Payload &>
SinkId molpro::linalg::itsolv::Logger::on ( F &&  f)
inline

Registers f(const log::Record &, const Ctx::Payload &) to be called for every event of context Ctx.

The subscription is not subject to the logger's thresholds or its data-dump flag.

Returns
An id that can be passed to remove_sink()

◆ remove_sink()

void molpro::linalg::itsolv::Logger::remove_sink ( SinkId  id)
inline

Removes a previously registered sink.

◆ set_default_output()

void molpro::linalg::itsolv::Logger::set_default_output ( bool  enable)
inline

Switches the built-in text output (default_message_handler()) on or off.

◆ set_min_severity()

void molpro::linalg::itsolv::Logger::set_min_severity ( log::Severity  severity)
inline

◆ set_verbosity()

void molpro::linalg::itsolv::Logger::set_verbosity ( log::Verbosity  verbosity)
inline

◆ trace()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::trace ( std::string_view  message,
const Ts &...  args 
) const
inline

◆ verbosity()

log::Verbosity molpro::linalg::itsolv::Logger::verbosity ( ) const
inline

◆ warn()

template<typename... Ts>
void molpro::linalg::itsolv::Logger::warn ( std::string_view  message,
const Ts &...  args 
) const
inline