|
VLink 2.0.0
A high-performance communication middleware
|
Global singleton logger with three output styles and pluggable backends. 更多...
#include <cstdio>#include <functional>#include <iomanip>#include <iostream>#include <memory>#include <string>#include <string_view>#include <type_traits>#include <utility>#include "./exception.h"#include "./fast_stream.h"#include "./format.h"#include "./macros.h"类 | |
| class | vlink::Logger |
| Global singleton logger supporting three output styles and configurable log levels. 更多... | |
| struct | vlink::Logger::NoDetail |
| Sentinel type indicating that no file/line detail is attached. 更多... | |
| class | vlink::Logger::WrapperStream< LevelT > |
| RAII stream wrapper that accumulates tokens and flushes on destruction. 更多... | |
命名空间 | |
| namespace | vlink |
类型定义 | |
| using | VLinkLogger = vlink::Logger |
Global singleton logger with three output styles and pluggable backends.
Logger is the central logging facility in VLink. It is a singleton accessed via Logger::get() and initialised once with Logger::init(). Log messages can be written to a console sink and/or a file sink, each with an independently configured minimum level.
Output styles:
| Style | Syntax | Notes |
|---|---|---|
| Stream style (LOG) | VLOG_I("x=", x) | Uses FastStream operator<<, zero allocation |
| Format style (MLOG) | MLOG_I("x={}", x) | Uses VLink format::format_to_n |
| C style (CLOG) | CLOG_I("x=%d", x) | Uses std::snprintf |
| RAII stream (SLOG) | SLOG_I << "x=" << x | WrapperStream, flushed on destruction |
Log levels:
| Value | Name | Use case |
|---|---|---|
| 0 | kTrace | Verbose internals |
| 1 | kDebug | Developer diagnostics |
| 2 | kInfo | Normal operational messages |
| 3 | kWarn | Unusual but recoverable conditions |
| 4 | kError | Errors that may affect operation |
| 5 | kFatal | Unrecoverable errors; throws RuntimeError |
| 6 | kOff | Disables all output |
Detail annotation: When the log level is >= kDetailLevel (default: kWarn), the macro automatically prepends {filename:line} to the message to aid in debugging.
Compile-time filtering:
VLINK_LOG_LEVEL=N to strip levels below N at compile time (zero overhead).VLINK_LOG_DETAIL_LEVEL=N to change the threshold at which file/line is shown.VLINK_LOG_DISABLE_SHORT to suppress the short VLOG_* aliases.Backtrace support: When enabled via enable_backtrace(n), the last n log messages are kept in a ring buffer and can be flushed on demand with dump_backtrace().
Backend support: The logger dispatches to spdlog, quill, DLT (automotive), Android logcat, QNX slog2, or kmsg depending on compile-time configuration. Custom backends can be registered with register_console_handler() / register_file_handler().
kFatal logs flush the logger and then throw Exception::RuntimeError.WrapperStream class is template-based; unused log levels are compiled away.| #define CLOG_D | ( | ... | ) |
| #define CLOG_E | ( | ... | ) |
| #define CLOG_F | ( | ... | ) |
| #define CLOG_I | ( | ... | ) |
| #define CLOG_T | ( | ... | ) |
| #define CLOG_W | ( | ... | ) |
| #define MLOG_D | ( | ... | ) |
| #define MLOG_E | ( | ... | ) |
| #define MLOG_F | ( | ... | ) |
| #define MLOG_I | ( | ... | ) |
| #define MLOG_T | ( | ... | ) |
| #define MLOG_W | ( | ... | ) |
| #define SLOG_D VLINK_SLOG_D |
| #define SLOG_E VLINK_SLOG_E |
| #define SLOG_F VLINK_SLOG_F |
| #define SLOG_I VLINK_SLOG_I |
| #define SLOG_T VLINK_SLOG_T |
| #define SLOG_W VLINK_SLOG_W |
| #define VLINK_CLOG_D | ( | ... | ) |
| #define VLINK_CLOG_E | ( | ... | ) |
| #define VLINK_CLOG_F | ( | ... | ) |
| #define VLINK_CLOG_I | ( | ... | ) |
| #define VLINK_CLOG_T | ( | ... | ) |
| #define VLINK_CLOG_W | ( | ... | ) |
| #define VLINK_LOG_D | ( | ... | ) |
| #define VLINK_LOG_E | ( | ... | ) |
| #define VLINK_LOG_F | ( | ... | ) |
| #define VLINK_LOG_GET_DETAIL | ( | level | ) |
Macro Definitions
| #define VLINK_LOG_HEX | ( | offset | ) |
| #define VLINK_LOG_HEXSS | ( | offset | ) |
| #define VLINK_LOG_I | ( | ... | ) |
| #define VLINK_LOG_IF_D VLinkLogger::is_writable(VLinkLogger::kDebug) |
| #define VLINK_LOG_IF_E VLinkLogger::is_writable(VLinkLogger::kError) |
| #define VLINK_LOG_IF_F VLinkLogger::is_writable(VLinkLogger::kFatal) |
| #define VLINK_LOG_IF_I VLinkLogger::is_writable(VLinkLogger::kInfo) |
| #define VLINK_LOG_IF_T VLinkLogger::is_writable(VLinkLogger::kTrace) |
| #define VLINK_LOG_IF_W VLinkLogger::is_writable(VLinkLogger::kWarn) |
| #define VLINK_LOG_T | ( | ... | ) |
| #define VLINK_LOG_W | ( | ... | ) |
| #define VLINK_MLOG_D | ( | ... | ) |
| #define VLINK_MLOG_E | ( | ... | ) |
| #define VLINK_MLOG_F | ( | ... | ) |
| #define VLINK_MLOG_I | ( | ... | ) |
| #define VLINK_MLOG_T | ( | ... | ) |
| #define VLINK_MLOG_W | ( | ... | ) |
| #define VLINK_SLOG_D VLinkLogger::WrapperStream<VLinkLogger::kDebug>(VLINK_LOG_GET_DETAIL(VLinkLogger::kDebug)) |
| #define VLINK_SLOG_E VLinkLogger::WrapperStream<VLinkLogger::kError>(VLINK_LOG_GET_DETAIL(VLinkLogger::kError)) |
| #define VLINK_SLOG_F VLinkLogger::WrapperStream<VLinkLogger::kFatal>(VLINK_LOG_GET_DETAIL(VLinkLogger::kFatal)) |
| #define VLINK_SLOG_I VLinkLogger::WrapperStream<VLinkLogger::kInfo>(VLINK_LOG_GET_DETAIL(VLinkLogger::kInfo)) |
| #define VLINK_SLOG_T VLinkLogger::WrapperStream<VLinkLogger::kTrace>(VLINK_LOG_GET_DETAIL(VLinkLogger::kTrace)) |
| #define VLINK_SLOG_W VLinkLogger::WrapperStream<VLinkLogger::kWarn>(VLINK_LOG_GET_DETAIL(VLinkLogger::kWarn)) |
| #define VLOG_D | ( | ... | ) |
| #define VLOG_E | ( | ... | ) |
| #define VLOG_F | ( | ... | ) |
| #define VLOG_I | ( | ... | ) |
| #define VLOG_T | ( | ... | ) |
| #define VLOG_W | ( | ... | ) |
| using VLinkLogger = vlink::Logger |