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

logger 对外包含入口 / Public include entry for logger More...

Enumerations

enum class  Frontend : uint8_t { Auto , Format , Printf }
 Logger 字面量前端选择模式 / Logger literal frontend selection mode. More...
 
enum class  Resolution : uint8_t { None , Format , Printf , Ambiguous }
 将一条 logger 字面量与可用前端进行解析后的结果。 Result of resolving one logger literal against the available frontends. More...
 

Functions

template<Print::Text Source>
consteval bool UsesFormatSyntax ()
 判断一条合法 brace 字面量是否真的使用了 brace 语法。 Returns whether one valid brace literal actually uses brace syntax.
 
template<Print::Text Source>
consteval bool UsesPrintfSyntax ()
 判断一条合法 printf 字面量是否真的使用了 printf 语法。 Returns whether one valid printf literal actually uses printf syntax.
 
template<Print::Text Source>
consteval bool FormatSourceValid ()
 判断一条 brace 风格源串在源级上是否合法。 Returns whether one brace-style source is source-level valid.
 
template<Print::Text Source>
consteval bool PrintfSourceValid ()
 判断一条 printf 风格源串在源级上是否合法。 Returns whether one printf-style source is source-level valid.
 
template<Print::Text Source, typename... Args>
consteval bool FormatMatches ()
 判断一组参数是否能被 brace 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity first.
 
template<Print::Text Source, typename... Args>
consteval bool PrintfMatches ()
 判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the printf frontend, guarded by source-level validity first.
 
template<Frontend Forced, Print::Text Source, typename... Args>
consteval Resolution ResolveFrontend ()
 为一条 logger 字面量及一组具体参数选择前端。 Selects the logger frontend for one literal plus one concrete argument list.
 
template<Frontend Forced, Print::Text Source, typename... Args>
consteval Frontend SelectFrontend ()
 在校验解析结果后,选择最终 logger 前端。 Selects the final logger frontend after validating the resolution result.
 

Detailed Description

logger 对外包含入口 / Public include entry for logger

Note
外部代码仍应优先包含这个头;字面量前端选择和日志宏定义已拆到同目录的内部片段。 External code should still include this header first; literal-frontend selection and log macro definitions are split into internal fragments in the same directory.

logger 字面量前端解析片段 / Logger literal-frontend resolution fragment

Logger 的字面量前端选择片段 Literal-frontend selection fragment of Logger

Note
这一组 helper 只负责在编译期判断一条日志字面量和一组参数应该落到 brace 前端还是 printf 前端,不直接处理运行时 topic 发布。 This helper set is responsible only for deciding at compile time whether one log literal plus one argument list should route to the brace frontend or the printf frontend; it does not perform runtime topic publication directly.

Enumeration Type Documentation

◆ Frontend

enum class LibXR::Detail::LoggerLiteral::Frontend : uint8_t
strong

Logger 字面量前端选择模式 / Logger literal frontend selection mode.

Enumerator
Auto 

自动选择 brace 或 printf / select brace or printf automatically

Format 

强制使用 brace 风格前端 / force brace-style frontend

Printf 

强制使用 printf 风格前端 / force printf-style frontend

Definition at line 18 of file logger.hpp.

◆ Resolution

enum class LibXR::Detail::LoggerLiteral::Resolution : uint8_t
strong

将一条 logger 字面量与可用前端进行解析后的结果。 Result of resolving one logger literal against the available frontends.

Enumerator
None 

两个前端都不匹配 / matches neither frontend

Format 

选择 brace 风格前端 / select brace-style frontend

Printf 

选择 printf 风格前端 / select printf-style frontend

Ambiguous 

两个前端都可用且都真的使用了自己的语法 both frontends remain valid and both syntaxes are used

Definition at line 30 of file logger.hpp.

31 : uint8_t
32{
@ XR_LOG_LEVEL_INFO
一般信息 / Informational message
@ XR_LOG_LEVEL_DEBUG
调试信息 / Debug message
@ XR_LOG_LEVEL_WARN
警告信息 / Warning message
@ XR_LOG_LEVEL_ERROR
错误信息 / Error message
@ XR_LOG_LEVEL_PASS
通过信息 / Pass message

Function Documentation

◆ FormatMatches()

template<Print::Text Source, typename... Args>
bool LibXR::Detail::LoggerLiteral::FormatMatches ( )
nodiscardconsteval

判断一组参数是否能被 brace 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity first.

logger 自动检测不能把多余实参当作 brace 字面量的无害输入,否则不受支持的 printf 风格源串可能回退成 brace 纯文本并静默丢弃实参。 Logger auto-detection must not treat extra call-site arguments as harmless for brace literals, otherwise unsupported printf-like sources can fall back to brace plain text and silently drop their arguments.

Definition at line 107 of file logger.hpp.

◆ FormatSourceValid()

template<Print::Text Source>
bool LibXR::Detail::LoggerLiteral::FormatSourceValid ( )
nodiscardconsteval

判断一条 brace 风格源串在源级上是否合法。 Returns whether one brace-style source is source-level valid.

Definition at line 78 of file logger.hpp.

◆ PrintfMatches()

template<Print::Text Source, typename... Args>
bool LibXR::Detail::LoggerLiteral::PrintfMatches ( )
nodiscardconsteval

判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the printf frontend, guarded by source-level validity first.

Definition at line 125 of file logger.hpp.

134 {
135 constexpr LibXR::Format<Source> format{};

◆ PrintfSourceValid()

template<Print::Text Source>
bool LibXR::Detail::LoggerLiteral::PrintfSourceValid ( )
nodiscardconsteval

判断一条 printf 风格源串在源级上是否合法。 Returns whether one printf-style source is source-level valid.

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(...)");
@ Auto
自动选择 brace 或 printf / select brace or printf automatically

◆ ResolveFrontend()

template<Frontend Forced, Print::Text Source, typename... Args>
Resolution LibXR::Detail::LoggerLiteral::ResolveFrontend ( )
nodiscardconsteval

为一条 logger 字面量及一组具体参数选择前端。 Selects the logger frontend for one literal plus one concrete argument list.

Definition at line 143 of file logger.hpp.

◆ SelectFrontend()

template<Frontend Forced, Print::Text Source, typename... Args>
Frontend LibXR::Detail::LoggerLiteral::SelectFrontend ( )
nodiscardconsteval

在校验解析结果后,选择最终 logger 前端。 Selects the final logger frontend after validating the resolution result.

Definition at line 198 of file logger.hpp.

208{
209
222#include "literal.hpp"
223
228enum class LogLevel : uint8_t
229{
235};
236
241struct LogData
242{
243 LogLevel level;
244 const char* file;
245 uint32_t line;
246 char message[XR_LOG_MESSAGE_MAX_LEN];
247};
248
253class Logger
254{
255 public:
259 static void Init();
260
268 template <Print::Text Source, typename... Args>
269 static void Publish(LogLevel level, const char* file, uint32_t line, Args&&... args)
270 {
271 constexpr auto frontend =
273 Source, Args...>();
274 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
275 }
276
285 template <Detail::LoggerLiteral::Frontend Forced, Print::Text Source, typename... Args>
286 static void Publish(LogLevel level, const char* file, uint32_t line, Args&&... args)
287 {
288 static_assert(
290 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
291
292 constexpr auto frontend =
293 Detail::LoggerLiteral::SelectFrontend<Forced, Source, Args...>();
294 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
295 }
296
297 private:
315 template <Detail::LoggerLiteral::Frontend FrontendMode, Print::Text Source,
316 typename... Args>
317 static void PublishSelected(LogLevel level, const char* file, uint32_t line,
318 Args&&... args)
319 {
320 if (!initialized_)
321 {
322 Init();
323 }
324
325 LogData data;
326 data.level = level;
327 data.file = file;
328 data.line = line;
329
330 if constexpr (FrontendMode == Detail::LoggerLiteral::Frontend::Format)
331 {
332 constexpr LibXR::Format<Source> format{};
333 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
334 std::forward<Args>(args)...);
335 UNUSED(written);
336 }
337 else
338 {
339 constexpr auto format = Print::Printf::Build<Source>();
340 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
341 std::forward<Args>(args)...);
342 UNUSED(written);
343 }
344
345 PublishToTopic(data);
346 }
347
353 static void PublishToTopic(LogData& data);
354
355 static inline bool initialized_ =
356 false;
358};
359
360} // namespace LibXR
361
365#include "macros.hpp"
日志管理器 / LibXR Logger Manager
Definition logger.hpp:57
Frontend
Logger 字面量前端选择模式 / Logger literal frontend selection mode.
Definition literal.hpp:18
@ Format
强制使用 brace 风格前端 / force brace-style frontend
consteval Frontend SelectFrontend()
在校验解析结果后,选择最终 logger 前端。 Selects the final logger frontend after validating the resolution result.
Definition literal.hpp:197
LogLevel
日志级别枚举 / Log level enumeration
Definition logger.hpp:32
日志数据结构体 / Log data structure
Definition logger.hpp:45
作为 printf 格式源的结构化字符串字面量包装 / Structural literal wrapper used as the NTTP source for printf formats
Definition printf.hpp:17

◆ UsesFormatSyntax()

template<Print::Text Source>
bool LibXR::Detail::LoggerLiteral::UsesFormatSyntax ( )
nodiscardconsteval

判断一条合法 brace 字面量是否真的使用了 brace 语法。 Returns whether one valid brace literal actually uses brace syntax.

Definition at line 44 of file logger.hpp.

45{
46 LogLevel level;
47 const char* file;
48 uint32_t line;
49 char message[XR_LOG_MESSAGE_MAX_LEN];
50};
51

◆ UsesPrintfSyntax()

template<Print::Text Source>
bool LibXR::Detail::LoggerLiteral::UsesPrintfSyntax ( )
nodiscardconsteval

判断一条合法 printf 字面量是否真的使用了 printf 语法。 Returns whether one valid printf literal actually uses printf syntax.

Definition at line 61 of file logger.hpp.