Logger

class Logger

Process-wide logging facility with a pluggable handler.

A thin wrapper around four severity levels that by default prints to stdout. Call set_log_handler to redirect messages elsewhere, for example into a host application’s own logging system; clear_log_handler restores the default printer.

Public Types

enum LogLevel

Severity of a logged message.

Values:

enumerator level_debug
enumerator level_info
enumerator level_warning
enumerator level_error
using LogHandlerFunc = std::function<void(LogLevel level, const std::string &message)>

Signature of a custom log handler; see set_log_handler.

Public Static Functions

static inline void log(LogLevel level, const std::string &message)

Dispatch message at level to the current handler, or print it.

static inline void debug(const std::string &message)

Log message at level_debug.

static inline void info(const std::string &message)

Log message at level_info.

static inline void warning(const std::string &message)

Log message at level_warning.

static inline void error(const std::string &message)

Log message at level_error.

static inline void set_log_handler(LogHandlerFunc func)

Route every future log call through func instead of printing.

static inline void clear_log_handler()

Remove a handler set with set_log_handler and resume printing.