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{
38};
@ 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 108 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 79 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 126 of file logger.hpp.

134 {
135 constexpr LibXR::Format<Source> format{};
136 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 90 of file logger.hpp.

90 {
91 static_assert(
93 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
94
@ 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 144 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 199 of file logger.hpp.

209{
210
223#include "literal.hpp"
224
229enum class LogLevel : uint8_t
230{
236};
237
242struct LogData
243{
244 LogLevel level;
245 const char* file;
246 uint32_t line;
247 char message[XR_LOG_MESSAGE_MAX_LEN];
248};
249
254class Logger
255{
256 public:
260 static void Init();
261
269 template <Print::Text Source, typename... Args>
270 static void Publish(LogLevel level, const char* file, uint32_t line, Args&&... args)
271 {
272 constexpr auto frontend =
274 Source, Args...>();
275 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
276 }
277
286 template <Detail::LoggerLiteral::Frontend Forced, Print::Text Source, typename... Args>
287 static void Publish(LogLevel level, const char* file, uint32_t line, Args&&... args)
288 {
289 static_assert(
291 "LibXR::Logger: explicit literal tag must be XR_FMT(...) or XR_PRINTF(...)");
292
293 constexpr auto frontend =
294 Detail::LoggerLiteral::SelectFrontend<Forced, Source, Args...>();
295 PublishSelected<frontend, Source>(level, file, line, std::forward<Args>(args)...);
296 }
297
298 private:
316 template <Detail::LoggerLiteral::Frontend FrontendMode, Print::Text Source,
317 typename... Args>
318 static void PublishSelected(LogLevel level, const char* file, uint32_t line,
319 Args&&... args)
320 {
321 if (!initialized_)
322 {
323 Init();
324 }
325
326 LogData data;
327 data.level = level;
328 data.file = file;
329 data.line = line;
330
331 if constexpr (FrontendMode == Detail::LoggerLiteral::Frontend::Format)
332 {
333 constexpr LibXR::Format<Source> format{};
334 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
335 std::forward<Args>(args)...);
336 UNUSED(written);
337 }
338 else
339 {
340 constexpr auto format = Print::Printf::Build<Source>();
341 auto written = Print::FormatIntoBuffer(data.message, sizeof(data.message), format,
342 std::forward<Args>(args)...);
343 UNUSED(written);
344 }
345
346 PublishToTopic(data);
347 }
348
354 static void PublishToTopic(LogData& data);
355
356 static inline bool initialized_ =
357 false;
359};
360
361} // namespace LibXR
362
366#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:198
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

Returns whether one valid brace literal actually uses brace syntax.

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

Definition at line 45 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 62 of file logger.hpp.