libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Logger Class Reference

日志管理器 / LibXR Logger Manager More...

#include <logger.hpp>

Static Public Member Functions

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
 

Detailed Description

日志管理器 / LibXR Logger Manager

Definition at line 56 of file logger.hpp.

Member Function Documentation

◆ Init()

void Logger::Init ( )
static

初始化日志主题 / 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 121 of file logger.cpp.

122{
123 log_topic = Topic::CreateTopic<LogData>("/xr/log", nullptr, true);
124
125 auto log_cb = LibXR::Topic::Callback::Create(OnLogMessage, log_topic);
126 log_topic.RegisterCallback(log_cb);
127
128 initialized_ = true;
129}
static Callback Create(Callable fun, BoundArg arg)
创建一个回调订阅句柄 / Create a callback subscription handle
Definition callback.hpp:519
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
Definition topic.hpp:362

◆ Publish() [1/2]

template<Print::Text Source, typename... Args>
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...>();
77 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
78 }
consteval Frontend SelectFrontend()
在校验解析结果后,选择最终 logger 前端。 Selects the final logger frontend after validating the resolution result.
Definition logger.hpp:198
@ Auto
自动选择 brace 或 printf / select brace or printf automatically

◆ Publish() [2/2]

template<Detail::LoggerLiteral::Frontend Forced, Print::Text Source, typename... Args>
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 {
91 static_assert(
93 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
94
95 constexpr auto frontend =
96 Detail::LoggerLiteral::SelectFrontend<Forced, Source, Args...>();
97 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
98 }

The documentation for this class was generated from the following files: