日志管理器 / LibXR Logger Manager
More...
#include <logger.hpp>
|
| static void | Init () |
| | 初始化日志主题 / Initialize the log topic
|
| |
| template<Print::Text Source, typename... Args> |
| static void | Publish (LogLevel level, const char *file, uint32_t line, Args &&... args) |
| | 发布一条字面量日志 / Publish one literal log message
|
| |
| template<Detail::LoggerLiteral::Frontend Forced, Print::Text Source, typename... Args> |
| static void | Publish (LogLevel level, const char *file, uint32_t line, Args &&... args) |
| | 发布一条带显式前端标签的字面量日志 / Publish one literal log message with an explicit frontend tag
|
| |
|
| static bool | initialized_ = false |
| | 是否已经完成日志 topic 初始化 / Whether logger-topic initialization has completed.
|
| |
日志管理器 / LibXR Logger Manager
Definition at line 56 of file logger.hpp.
◆ Init()
初始化日志主题 / Initialize the log topic
初始化 logger 的内部 topic 与终端订阅路径 Initialize the logger's internal topic and terminal subscriber path
- Note
- 这里只做一次性初始化:创建
/xr/log topic,并注册一个把日志打印到 STDIO 的 callback。 This performs one-time initialization only: create the /xr/log topic and register one callback that prints logs to STDIO.
Definition at line 119 of file logger.cpp.
120{
122
124 log_topic.RegisterCallback(log_cb);
125
127}
static bool initialized_
是否已经完成日志 topic 初始化 / Whether logger-topic initialization has completed.
static Callback Create(Callable fun, BoundArg arg)
创建一个回调订阅句柄 / Create a callback subscription handle
static Topic CreateTopic(const char *name, Domain *domain=nullptr, bool multi_publisher=false)
用精确类型创建或查找一个 topic / Create or look up one topic using one exact payload type
◆ Publish() [1/2]
| static void LibXR::Logger::Publish |
( |
LogLevel | level, |
|
|
const char * | file, |
|
|
uint32_t | line, |
|
|
Args &&... | args ) |
|
inlinestatic |
发布一条字面量日志 / Publish one literal log message
- Parameters
-
| level | 日志级别 / Log level |
| file | 来源文件名 / Source file name |
| line | 行号 / Line number |
| args | 格式参数 / Format arguments |
Definition at line 72 of file logger.hpp.
73 {
74 constexpr auto frontend =
76 Source, Args...>();
78 }
static void PublishSelected(LogLevel level, const char *file, uint32_t line, Args &&... args)
按已确定前端发布一条日志 Publish one log entry under the already selected frontend
consteval Frontend SelectFrontend()
Selects the final logger frontend after validating the resolution result.
@ Auto
select brace or printf automatically / 自动选择 brace 或 printf
◆ Publish() [2/2]
| static void LibXR::Logger::Publish |
( |
LogLevel | level, |
|
|
const char * | file, |
|
|
uint32_t | line, |
|
|
Args &&... | args ) |
|
inlinestatic |
发布一条带显式前端标签的字面量日志 / Publish one literal log message with an explicit frontend tag
- Parameters
-
| level | 日志级别 / Log level |
| file | 来源文件名 / Source file name |
| line | 行号 / Line number |
| args | 格式参数 / Format arguments |
Definition at line 89 of file logger.hpp.
90 {
92 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
93
94 constexpr auto frontend =
97 }
◆ PublishSelected()
| static void LibXR::Logger::PublishSelected |
( |
LogLevel | level, |
|
|
const char * | file, |
|
|
uint32_t | line, |
|
|
Args &&... | args ) |
|
inlinestaticprivate |
按已确定前端发布一条日志 Publish one log entry under the already selected frontend
- Template Parameters
-
| FrontendMode | 已选定的日志字面量前端 / Already selected literal frontend |
| Source | 日志源串 / Log source literal |
| Args | 格式参数类型 / Format argument types |
- Parameters
-
| level | 日志级别 / Log level |
| file | 来源文件名 / Source file name |
| line | 行号 / Line number |
| args | 格式参数 / Format arguments |
- Note
- 这里负责惰性初始化日志主题,并把格式化后的文本写进固定
LogData 缓冲区; 真正的 topic 发布留给 PublishToTopic()。 This path performs lazy logger-topic initialization and formats the final text into the fixed LogData buffer; the actual topic publish is delegated to PublishToTopic().
Definition at line 119 of file logger.hpp.
121 {
123 {
125 }
126
127 LogData data;
128 data.level = level;
129 data.file = file;
130 data.line = line;
131
133 {
135 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
136 std::forward<Args>(args)...);
137 UNUSED(written);
138 }
139 else
140 {
142 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
143 std::forward<Args>(args)...);
144 UNUSED(written);
145 }
146
148 }
static void PublishToTopic(LogData &data)
把一条日志数据发布到内部日志 topic Publish one log record into the internal log topic
static void Init()
初始化日志主题 / Initialize the log topic
static consteval Compiled< Source > Build()
在编译期解析并校验 printf 格式串 / Parse and validate a printf format at compile time
@ Format
force brace-style frontend / 强制使用 brace 风格前端
◆ PublishToTopic()
| void Logger::PublishToTopic |
( |
LogData & | data | ) |
|
|
staticprivate |
把一条日志数据发布到内部日志 topic Publish one log record into the internal log topic
把一条日志发布到内部日志 topic Publish one log record into the internal log topic
- Parameters
-
| data | 待发布日志 / Log record to publish |
Definition at line 134 of file logger.cpp.
134{ log_topic.Publish(data); }
◆ initialized_
| bool LibXR::Logger::initialized_ = false |
|
inlinestaticprivate |
是否已经完成日志 topic 初始化 / Whether logger-topic initialization has completed.
Definition at line 157 of file logger.hpp.
The documentation for this class was generated from the following files: