|
VLink
2.0.0
A high-performance communication middleware
|
Global singleton logger with four formatting styles and independently configurable sinks. More...
#include <logger.h>
Classes | |
| struct | NoDetail |
| Sentinel type indicating no detail prefix is attached. More... | |
| class | WrapperStream |
RAII helper backing SLOG_*; collects tokens and flushes on destruction. More... | |
Public Types | |
| enum | Style : uint8_t { kStreamStyle = 0 , kFormatStyle = 1 , kCStyle = 2 } |
Internal output style tag used by the print_* family. More... | |
| enum | Level : uint8_t { kTrace = 0 , kDebug = 1 , kInfo = 2 , kWarn = 3 , kError = 4 , kFatal = 5 , kOff = 6 } |
| Message severity level. More... | |
| using | Callback = MoveFunction< void(Level, std::string_view)> |
| Signature for custom console / file sink callbacks. More... | |
| using | DetailInfo = std::pair< std::string_view, int > |
| Carries the source file name and line number for the detail prefix. More... | |
Public Member Functions | |
| template<Logger::Level LevelT, typename DetailT , typename... ArgsT> | |
| void | print_stream_style ([[maybe_unused]] DetailT &&detail, [[maybe_unused]] ArgsT &&... args) |
| template<Logger::Level LevelT, typename DetailT , typename... ArgsT> | |
| void | print_format_style ([[maybe_unused]] DetailT &&detail, [[maybe_unused]] format::format_string< ArgsT... > format, [[maybe_unused]] ArgsT &&... args) |
| template<Logger::Level LevelT, typename DetailT , typename FormatT , typename... ArgsT> | |
| void | print_c_style ([[maybe_unused]] DetailT &&detail, [[maybe_unused]] FormatT &&format, [[maybe_unused]] ArgsT &&... args) |
| template<Logger::Level LevelT, typename... ArgsT> | |
| void | print ([[maybe_unused]] ArgsT &&... args) |
Static Public Member Functions | |
| static void | init (const std::string &app_name="", const std::string &log_path="") noexcept |
| Initialises the logger singleton. More... | |
| static Logger & | get () noexcept |
| Returns the global logger instance. More... | |
| static void | flush () noexcept |
| Flushes every active sink. More... | |
| static void | register_console_handler (Callback &&callback) noexcept |
| Installs a custom console sink callback replacing the built-in console writer. More... | |
| static void | register_file_handler (Callback &&callback) noexcept |
| Installs a custom file sink callback replacing the built-in file writer. More... | |
| static void | set_console_level (Level level) noexcept |
Sets the minimum severity for the console sink; pass kOff to mute it. More... | |
| static void | set_file_level (Level level) noexcept |
Sets the minimum severity for the file sink; pass kOff to mute it. More... | |
| static void | set_console_fmt_enable (bool enable) noexcept |
| Enables or disables ANSI colour / formatting on the console sink. More... | |
| static Level | get_console_level () noexcept |
| Returns the current console sink severity threshold. More... | |
| static Level | get_file_level () noexcept |
| Returns the current file sink severity threshold. More... | |
| static bool | get_console_fmt_enable () noexcept |
| Returns whether ANSI colour codes are enabled on the console sink. More... | |
| static void | set_stream_flag (std::ios_base::fmtflags flags) noexcept |
Sets std::ios_base format flags applied to stream-style records. More... | |
| static void | set_stream_precision (int precision) noexcept |
| Sets the floating-point precision for stream-style records. More... | |
| static void | set_stream_width (int width) noexcept |
| Sets the minimum field width for stream-style records. More... | |
| static std::ios_base::fmtflags | get_stream_flag () noexcept |
| Returns the stream format flags currently applied to stream-style records. More... | |
| static int | get_stream_precision () noexcept |
| Returns the floating-point precision used for stream-style records. More... | |
| static int | get_stream_width () noexcept |
| Returns the field width used for stream-style records. More... | |
| static void | enable_backtrace (size_t size) noexcept |
Enables a ring-buffer backtrace of the most recent size records. More... | |
| static void | disable_backtrace () noexcept |
| Disables backtrace capture and discards the ring buffer. More... | |
| static void | dump_backtrace () noexcept |
| Flushes the backtrace ring buffer to the active sinks. More... | |
| static bool | is_busy () noexcept |
| Reports whether the logger is currently writing a record. More... | |
| static bool | is_writable (Level level) noexcept |
Reports whether a record at level would currently be emitted. More... | |
| static constexpr std::string_view | extract_filename (std::string_view path) noexcept |
| Strips a path down to its final filename component at compile time. More... | |
| template<Level LevelT, typename DetailT , typename... ArgsT> | |
| static void | print_stream_style (DetailT &&detail, ArgsT &&... args) |
Stream-style entry point (used by VLOG_* / print). More... | |
| template<Level LevelT, typename DetailT , typename... ArgsT> | |
| static void | print_format_style (DetailT &&detail, format::format_string< ArgsT... > format, ArgsT &&... args) |
Placeholder-style entry point (used by MLOG_*). More... | |
| template<Logger::Level LevelT, typename DetailT , typename FormatT , typename... ArgsT> | |
| static void | print_c_style (DetailT &&detail, FormatT &&format, ArgsT &&... args) |
printf-style entry point (used by CLOG_*). More... | |
| template<Level LevelT, typename... ArgsT> | |
| static void | print (ArgsT &&... args) |
| Convenience stream-style entry point without source location. More... | |
Static Public Attributes | |
| static constexpr uint8_t | kMinimumLevel = kTrace |
| Compile-time minimum severity level; messages below this are stripped. More... | |
| static constexpr uint8_t | kDetailLevel = kWarn |
Severity threshold at and above which {file:line} is prepended to messages. More... | |
| static constexpr int | kLocalBufferSize = 4096 |
| Size of the thread-local C-style format buffer in bytes. More... | |
Friends | |
| template<Logger::Level LevelT> | |
| class | WrapperStream |
Global singleton logger with four formatting styles and independently configurable sinks.
Construct exactly once via Logger::init; subsequent calls reconfigure the existing instance. The console sink is always enabled; the file sink activates when log_path is non-empty. Logging entry points are macros that wrap the public print_* templates and forward a compile-time Level so the bodies disappear when the level is below kMinimumLevel.
| using vlink::Logger::Callback = MoveFunction<void(Level, std::string_view)> |
Signature for custom console / file sink callbacks.
Invoked synchronously from the logging thread; the std::string_view is valid only for the duration of the call.
| using vlink::Logger::DetailInfo = std::pair<std::string_view, int> |
Carries the source file name and line number for the detail prefix.
Built automatically by VLINK_LOG_GET_DETAIL when the message level reaches kDetailLevel.
| enum vlink::Logger::Level : uint8_t |
Message severity level.
Lower numerical values are less severe. kOff is a sentinel that disables a sink.
| Enumerator | |
|---|---|
| kTrace | Verbose tracing. |
| kDebug | Developer diagnostics. |
| kInfo | Normal operational message. |
| kWarn | Recoverable but unusual condition. |
| kError | Recoverable error. |
| kFatal | Unrecoverable; throws |
| kOff | Disable sink. |
| enum vlink::Logger::Style : uint8_t |
Internal output style tag used by the print_* family.
Callers normally interact with styles via macros; the enum is exposed for completeness.
| Enumerator | |
|---|---|
| kStreamStyle | Stream composition via |
| kFormatStyle | Brace placeholders via |
| kCStyle | printf-style formatting via |
|
staticnoexcept |
Disables backtrace capture and discards the ring buffer.
|
staticnoexcept |
Flushes the backtrace ring buffer to the active sinks.
|
staticnoexcept |
Enables a ring-buffer backtrace of the most recent size records.
| size | Capacity of the backtrace ring buffer. |
|
inlinestaticconstexprnoexcept |
Strips a path down to its final filename component at compile time.
Details.
| path | Source path, typically FILE. |
|
staticnoexcept |
Flushes every active sink.
Useful before abnormal termination. Invoked automatically before a kFatal message throws.
|
staticnoexcept |
Returns the global logger instance.
|
staticnoexcept |
Returns whether ANSI colour codes are enabled on the console sink.
true when ANSI escapes are emitted.
|
staticnoexcept |
Returns the current console sink severity threshold.
|
staticnoexcept |
Returns the current file sink severity threshold.
|
staticnoexcept |
Returns the stream format flags currently applied to stream-style records.
|
staticnoexcept |
Returns the floating-point precision used for stream-style records.
|
staticnoexcept |
Returns the field width used for stream-style records.
|
staticnoexcept |
Initialises the logger singleton.
Must be invoked before any logging macros. Subsequent calls reconfigure the singleton. Provide a non-empty log_path to activate the file sink.
| app_name | Application name embedded in log output. Default: empty. |
| log_path | Absolute path for the file sink. Default: empty (no file sink). |
|
staticnoexcept |
Reports whether the logger is currently writing a record.
true while a write is in progress.
|
staticnoexcept |
Reports whether a record at level would currently be emitted.
Use the result to gate expensive argument computation before a macro call.
| level | Severity level under test. |
true when the level passes either sink threshold.
|
inline |
|
static |
Convenience stream-style entry point without source location.
| LevelT | Compile-time severity. |
| ArgsT | Stream argument types. |
| args | Values to stream. |
|
inline |
|
static |
printf-style entry point (used by CLOG_*).
| LevelT | Compile-time severity. |
| DetailT | Either DetailInfo or NoDetail. |
| FormatT | Format string type, typically const char*. |
| ArgsT | printf argument types. |
| detail | Source location info or NoDetail{}. |
| format | printf-style format string. |
| args | printf arguments. |
|
inline |
|
static |
|
inline |
|
static |
Stream-style entry point (used by VLOG_* / print).
Returns immediately when should_log<LevelT>() is false. Otherwise streams args into a thread-local FastStream and hands the resulting view to the sinks.
| LevelT | Compile-time severity. |
| DetailT | Either DetailInfo or NoDetail. |
| ArgsT | Stream argument types. |
| detail | Source location info or NoDetail{}. |
| args | Values to stream. |
|
staticnoexcept |
Installs a custom console sink callback replacing the built-in console writer.
| callback | Handler called with (level, message_view) for each record. |
|
staticnoexcept |
Installs a custom file sink callback replacing the built-in file writer.
| callback | Handler called with (level, message_view) for each record. |
|
staticnoexcept |
Enables or disables ANSI colour / formatting on the console sink.
| enable | true to keep ANSI escapes (default), false for plain text. |
|
staticnoexcept |
Sets the minimum severity for the console sink; pass kOff to mute it.
| level | Minimum output level. |
|
staticnoexcept |
Sets the minimum severity for the file sink; pass kOff to mute it.
| level | Minimum output level. |
|
staticnoexcept |
Sets std::ios_base format flags applied to stream-style records.
| flags | Stream format flags. |
|
staticnoexcept |
Sets the floating-point precision for stream-style records.
| precision | Precision passed to std::setprecision. |
|
staticnoexcept |
Sets the minimum field width for stream-style records.
| width | Field width passed to std::setw. |
|
friend |
|
staticconstexpr |
Severity threshold at and above which {file:line} is prepended to messages.
Override by defining VLINK_LOG_DETAIL_LEVEL before including this header. Defaults to kWarn.
|
staticconstexpr |
Size of the thread-local C-style format buffer in bytes.
Messages longer than kLocalBufferSize - 1 characters are silently truncated.
|
staticconstexpr |
Compile-time minimum severity level; messages below this are stripped.
Override by defining VLINK_LOG_LEVEL before including this header. Defaults to kTrace so every level is emitted by default.