5#include "libxr_def.hpp"
13static Topic log_topic;
22const char* GetLogColor(
LogLevel level)
26 case LogLevel::XR_LOG_LEVEL_DEBUG:
28 case LogLevel::XR_LOG_LEVEL_INFO:
30 case LogLevel::XR_LOG_LEVEL_PASS:
32 case LogLevel::XR_LOG_LEVEL_WARN:
34 case LogLevel::XR_LOG_LEVEL_ERROR:
48const char* LogLevelToString(
LogLevel level)
52 case LogLevel::XR_LOG_LEVEL_DEBUG:
54 case LogLevel::XR_LOG_LEVEL_INFO:
56 case LogLevel::XR_LOG_LEVEL_PASS:
58 case LogLevel::XR_LOG_LEVEL_WARN:
60 case LogLevel::XR_LOG_LEVEL_ERROR:
79 const char* color = GetLogColor(data.
level);
80 const uint32_t timestamp_ms =
81 static_cast<uint32_t
>(
static_cast<uint64_t
>(timestamp) / 1000U);
83 color, LogLevelToString(data.
level), timestamp_ms, data.
file, data.
line,
100 ASSERT(log_message.
data !=
nullptr);
102 if (LIBXR_LOG_OUTPUT_LEVEL >=
static_cast<uint8_t
>(log_message.
data->level) &&
105 PrintLogToTerminal(*log_message.
data, log_message.
timestamp);
static void PublishToTopic(LogData &data)
把一条日志数据发布到内部日志 topic Publish one log record into the internal log topic
static void Init()
初始化日志主题 / Initialize the log topic
static bool initialized_
是否已经完成日志 topic 初始化 / Whether logger-topic initialization has completed.
微秒时间戳 / Microsecond timestamp
static int Print(Args &&... args)
将一个编译期 brace 字面量打印到当前 STDIO 输出 / Print one compile-time brace literal to the active STDIO output
static WritePort * write_
Write port instance. 写入端口。
static Callback Create(Callable fun, BoundArg arg)
创建一个回调订阅句柄 / Create a callback subscription handle
发布订阅主题 / Publish-subscribe topic
void Publish(Data &data)
在普通上下文里发布一条消息,并自动取当前时间戳 / Publish one message in normal context and stamp it with the current time
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
void RegisterCallback(Callback &cb)
注册一个回调订阅者 / Register one callback subscriber
bool Writable()
判断端口是否可写。 Checks whether the port is writable.
constexpr const char * LIBXR_TERMINAL_CONTROL_STR[]
ANSI escape sequences for terminal controls / ANSI转义序列 - 终端控制
constexpr const char * LIBXR_FOREGROUND_STR[]
ANSI escape sequences for foreground colors / ANSI转义序列 - 前景色
LogLevel
日志级别枚举 / Log level enumeration
日志数据结构体 / Log data structure
uint32_t line
行号 / Line number
const char * file
文件名指针 / Source file name pointer
LogLevel level
日志级别 / Log level
char message[XR_LOG_MESSAGE_MAX_LEN]
日志消息内容 / Log message content
带时间戳和 payload 指针的只读消息视图 / Read-only message view carrying a timestamp and a payload pointer
Data * data
指向本次发布 payload 对象的指针。Pointer to the payload object of this publish.
MicrosecondTimestamp timestamp
消息时间戳。Message timestamp.