Files
XCEngine/docs/api/debug/loglevel/loglevel.md

95 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LogLevel
**命名空间**: `XCEngine::Debug`
**类型**: `enum class`
**头文件**: `XCEngine/Debug/LogLevel.h`
**描述**: 日志级别枚举,用于区分不同重要程度的日志消息
## 概述
LogLevel 枚举定义了六个日志级别从低到高依次为Verbose、Debug、Info、Warning、Error、Fatal。数值越高表示级别越严重便于日志系统进行过滤和分类处理。
## 枚举值
| 值 | 数值 | 描述 |
|----|------|------|
| `Verbose` | 0 | 详细日志,用于调试追踪 |
| `Debug` | 1 | 调试日志,开发时使用 |
| `Info` | 2 | 信息日志,一般信息提示 |
| `Warning` | 3 | 警告日志,潜在问题提示 |
| `Error` | 4 | 错误日志,已发生的错误 |
| `Fatal` | 5 | 致命日志,导致程序无法继续 |
## 公共函数
| 函数 | 描述 |
|------|------|
| [`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
#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) - Debug 模块介绍