LibXR 日志管理器 / LibXR Logger Manager.
More...
#include <logger.hpp>
LibXR 日志管理器 / LibXR Logger Manager.
Definition at line 44 of file logger.hpp.
◆ GetColor()
根据日志级别获取显示颜色 / Get color code based on log level
- Parameters
-
- Returns
- 颜色字符串 / Color string
Definition at line 84 of file logger.hpp.
85 {
86 using namespace LibXR;
87 switch (level)
88 {
99 default:
100 return "";
101 }
102 }
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
constexpr const char * LIBXR_FONT_STR[]
ANSI escape sequences for font color / ANSI转义序列 - 字体颜色
@ 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
◆ Init()
初始化日志主题 / Initialize the log topic
Definition at line 15 of file logger.cpp.
16{
17 log_topic = Topic::CreateTopic<LogData>("/xr/log", nullptr, false, true);
18
19#if LIBXR_PRINTF_BUFFER_SIZE > 0
22 {
24
26
29 {
31 }
32 };
33
36#endif
37
38 initialized_ = true;
39}
static Callback Create(FunType fun, ArgType arg)
创建一个新的回调对象,并绑定回调函数和参数。 Creates a new callback instance, binding a function and an argument.
static void PrintToTerminal(const LogData &data)
打印日志到终端 / Print log to terminal
原始数据封装类。 A class for encapsulating raw data.
static WritePort * write_
Write port instance. 写入端口。
主题(Topic)管理类 / Topic management class
void RegisterCallback(Callback< RawData & > &cb)
注册回调函数 Registers a callback function
bool Writable()
判断端口是否可写。 Checks whether the port is writable.
日志数据结构体 / Log data structure
◆ LevelToString()
将日志级别转换为字符串 / Convert log level to string
- Parameters
-
- Returns
- 日志级别字符串 / Log level string
Definition at line 109 of file logger.hpp.
110 {
111 switch (level)
112 {
114 return "DEBUG";
116 return "INFO";
118 return "PASS";
120 return "WARN";
122 return "ERROR";
123 default:
124 return "UNKNOWN";
125 }
126 }
◆ PrintToTerminal()
打印日志到终端 / Print log to terminal
- Parameters
-
Definition at line 69 of file logger.hpp.
70 {
71 const char* color =
GetColor(data.level);
72
75 data.file, data.line, data.message,
77 }
static const char * GetColor(LogLevel level)
根据日志级别获取显示颜色 / Get color code based on log level
static const char * LevelToString(LogLevel level)
将日志级别转换为字符串 / Convert log level to string
static int Printf(const char *fmt,...)
Prints a formatted string to the write port (like printf).
constexpr const char * LIBXR_FORMAT_STR[]
ANSI escape sequences for text format / ANSI转义序列 - 文本格式
◆ Publish()
发布一条日志 / Publish a log message
- Parameters
-
level | 日志级别 / Log level |
file | 来源文件名 / Source file name |
line | 行号 / Line number |
fmt | 格式化字符串 / Format string |
... | 可变参数 / Variable arguments |
Definition at line 42 of file logger.cpp.
44{
45 if (!initialized_)
46 {
48 }
54
60
62}
static void Init()
初始化日志主题 / Initialize the log topic
static uint32_t GetTime()
获取当前系统时间(毫秒) Gets the current system time in milliseconds
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
void Publish(Data &data)
发布数据 Publishes data
uint32_t line
行号 / Line number
const char * file
文件名指针 / Source file name pointer
LogLevel level
日志级别 / Log level
TimestampMS timestamp
时间戳 / Timestamp
char message[XR_LOG_MESSAGE_MAX_LEN]
日志消息内容 / Log message content
◆ initialized_
std::atomic<bool> LibXR::Logger::initialized_ = false |
|
inlinestaticprivate |
The documentation for this class was generated from the following files: