docs: update core and debug API docs
This commit is contained in:
@@ -4,37 +4,91 @@
|
||||
|
||||
**类型**: `enum class`
|
||||
|
||||
**描述**: 日志级别枚举,定义日志的严重程度。
|
||||
**头文件**: `XCEngine/Debug/LogLevel.h`
|
||||
|
||||
**描述**: 日志级别枚举,用于区分不同重要程度的日志消息
|
||||
|
||||
## 概述
|
||||
|
||||
`LogLevel` 枚举定义了从最详细到最严重的日志级别。`Logger` 根据设置的最小级别过滤日志。
|
||||
LogLevel 枚举定义了六个日志级别,从低到高依次为:Verbose、Debug、Info、Warning、Error、Fatal。数值越高表示级别越严重,便于日志系统进行过滤和分类处理。
|
||||
|
||||
## 枚举值
|
||||
|
||||
| 值 | 说明 | 数值 |
|
||||
| 值 | 数值 | 描述 |
|
||||
|----|------|------|
|
||||
| `Verbose` | 详细调试信息 | 0 |
|
||||
| `Debug` | 调试信息 | 1 |
|
||||
| `Info` | 一般信息 | 2 |
|
||||
| `Warning` | 警告信息 | 3 |
|
||||
| `Error` | 错误信息 | 4 |
|
||||
| `Fatal` | 致命错误 | 5 |
|
||||
| `Verbose` | 0 | 详细日志,用于调试追踪 |
|
||||
| `Debug` | 1 | 调试日志,开发时使用 |
|
||||
| `Info` | 2 | 信息日志,一般信息提示 |
|
||||
| `Warning` | 3 | 警告日志,潜在问题提示 |
|
||||
| `Error` | 4 | 错误日志,已发生的错误 |
|
||||
| `Fatal` | 5 | 致命日志,导致程序无法继续 |
|
||||
|
||||
## 辅助函数
|
||||
## 公共函数
|
||||
|
||||
| 函数 | 描述 |
|
||||
|------|------|
|
||||
| `const char* LogLevelToString(LogLevel level)` | [将日志级别转换为字符串](logleveltostring.md) |
|
||||
| [`LogLevelToString`](logleveltostring.md) | 将 LogLevel 转换为字符串表示 |
|
||||
|
||||
### LogLevelToString
|
||||
|
||||
```cpp
|
||||
const char* LogLevelToString(LogLevel level);
|
||||
```
|
||||
|
||||
将日志级别转换为对应的字符串名称。
|
||||
|
||||
**参数:**
|
||||
- `level` - 日志级别值
|
||||
|
||||
**返回:** 对应级别的字符串名称,如 "Verbose"、"Debug"、"Info" 等
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include "XCEngine/Debug/LogLevel.h"
|
||||
|
||||
int main() {
|
||||
using namespace XCEngine::Debug;
|
||||
|
||||
std::cout << LogLevelToString(LogLevel::Verbose) << std::endl; // Output: VERBOSE
|
||||
std::cout << LogLevelToString(LogLevel::Info) << std::endl; // Output: INFO
|
||||
std::cout << LogLevelToString(LogLevel::Error) << std::endl; // Output: ERROR
|
||||
|
||||
for (uint8_t i = 0; i <= 5; ++i) {
|
||||
LogLevel level = static_cast<LogLevel>(i);
|
||||
std::cout << static_cast<int>(level) << ": " << LogLevelToString(level) << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
Logger::Get().SetMinimumLevel(LogLevel::Warning);
|
||||
// 只有 Warning、Error、Fatal 级别的日志会被输出
|
||||
#include "XCEngine/Debug/LogLevel.h"
|
||||
|
||||
using namespace XCEngine::Debug;
|
||||
|
||||
void ProcessLog(LogLevel level, const char* message) {
|
||||
if (level >= LogLevel::Warning) {
|
||||
printf("[%s] %s\n", LogLevelToString(level), message);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
ProcessLog(LogLevel::Verbose, "This is verbose"); // Filtered out
|
||||
ProcessLog(LogLevel::Debug, "This is debug"); // Filtered out
|
||||
ProcessLog(LogLevel::Info, "This is info"); // Filtered out
|
||||
ProcessLog(LogLevel::Warning, "This is warning"); // Output: [WARNING] This is warning
|
||||
ProcessLog(LogLevel::Error, "This is error"); // Output: [ERROR] This is error
|
||||
ProcessLog(LogLevel::Fatal, "This is fatal"); // Output: [FATAL] This is fatal
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Debug 模块总览](../debug.md) - 返回模块总览
|
||||
- [Logger](../logger/logger.md) - 日志记录器
|
||||
- [Debug 模块总览](../debug.md) - Debug 模块介绍
|
||||
|
||||
Reference in New Issue
Block a user