libxr  1.0
Want to be the best embedded framework
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 literal frontend selection mode. More...
 
enum class  Resolution : uint8_t { None , Format , Printf , Ambiguous }
 Result of resolving one logger literal against the available frontends. More...
 

Functions

template<Print::Text Source>
consteval bool UsesFormatSyntax ()
 Returns whether one valid brace literal actually uses brace syntax.
 
template<Print::Text Source>
consteval bool UsesPrintfSyntax ()
 Returns whether one valid printf literal actually uses printf syntax.
 
template<Print::Text Source>
consteval bool FormatSourceValid ()
 Returns whether one brace-style source is source-level valid.
 
template<Print::Text Source>
consteval bool PrintfSourceValid ()
 Returns whether one printf-style source is source-level valid.
 
template<Print::Text Source, typename... Args>
consteval bool FormatMatches ()
 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 ()
 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 ()
 Selects the logger frontend for one literal plus one concrete argument list.
 
template<Frontend Forced, Print::Text Source, typename... Args>
consteval Frontend SelectFrontend ()
 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 literal frontend selection mode.

Logger 字面量前端选择模式。

Enumerator
Auto 

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

Format 

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

Printf 

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

Definition at line 19 of file logger.hpp.

◆ Resolution

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

Result of resolving one logger literal against the available frontends.

将一条 logger 字面量与可用前端进行解析后的结果。

Enumerator
None 

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

Format 

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

Printf 

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

Ambiguous 

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

Definition at line 31 of file logger.hpp.

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

Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity first.

判断一组参数是否能被 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. logger 自动检测不能把多余实参当作 brace 字面量的无害输入,否则不受支持的 printf 风格源串可能回退成 brace 纯文本并静默丢弃实参。

Definition at line 107 of file logger.hpp.

◆ FormatSourceValid()

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

Returns whether one brace-style source is source-level valid.

判断一条 brace 风格源串在源级上是否合法。

Definition at line 78 of file logger.hpp.

◆ PrintfMatches()

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

Returns whether one argument list is accepted by the printf frontend, guarded by source-level validity first.

判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。

Definition at line 125 of file logger.hpp.

133 {
134 constexpr LibXR::Format<Source> format{};
135 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,

◆ PrintfSourceValid()

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

Returns whether one printf-style source is source-level valid.

判断一条 printf 风格源串在源级上是否合法。

Definition at line 89 of file logger.hpp.

90 {
91 static_assert(Forced != Detail::LoggerLiteral::Frontend::Auto,
92 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
93
@ Auto
select brace or printf automatically / 自动选择 brace 或 printf

◆ ResolveFrontend()

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

Selects the logger frontend for one literal plus one concrete argument list.

为一条 logger 字面量及一组具体参数选择前端。

Definition at line 143 of file logger.hpp.

◆ SelectFrontend()

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

Selects the final logger frontend after validating the resolution result.

在校验解析结果后,选择最终 logger 前端。

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(Forced != Detail::LoggerLiteral::Frontend::Auto,
289 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
290
291 constexpr auto frontend =
292 Detail::LoggerLiteral::SelectFrontend<Forced, Source, Args...>();
293 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
294 }
295
296 private:
314 template <Detail::LoggerLiteral::Frontend FrontendMode, Print::Text Source,
315 typename... Args>
316 static void PublishSelected(LogLevel level, const char* file, uint32_t line,
317 Args&&... args)
318 {
319 if (!initialized_)
320 {
321 Init();
322 }
323
324 LogData data;
325 data.level = level;
326 data.file = file;
327 data.line = line;
328
329 if constexpr (FrontendMode == Detail::LoggerLiteral::Frontend::Format)
330 {
331 constexpr LibXR::Format<Source> format{};
332 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
333 std::forward<Args>(args)...);
334 UNUSED(written);
335 }
336 else
337 {
338 constexpr auto format = Print::Printf::Build<Source>();
339 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
340 std::forward<Args>(args)...);
341 UNUSED(written);
342 }
343
344 PublishToTopic(data);
345 }
346
352 static void PublishToTopic(LogData& data);
353
354 static inline bool initialized_ = false;
355};
356
357} // namespace LibXR
358
362#include "macros.hpp"
日志管理器 / LibXR Logger Manager
Definition logger.hpp:57
Frontend
Logger literal frontend selection mode.
Definition literal.hpp:19
@ Format
force brace-style frontend / 强制使用 brace 风格前端
consteval Frontend SelectFrontend()
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:16

◆ UsesFormatSyntax()

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

Returns whether one valid brace literal actually uses brace syntax.

判断一条合法 brace 字面量是否真的使用了 brace 语法。

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

Returns whether one valid printf literal actually uses printf syntax.

判断一条合法 printf 字面量是否真的使用了 printf 语法。

Definition at line 61 of file logger.hpp.