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

89 lines
2.3 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.
# Debug 模块概览
**命名空间**: `XCEngine::Debug`
**类型**: `module`
**头文件**: `XCEngine/Debug/Debug.h`
**描述**: XCEngine 的调试和日志模块,提供日志记录和性能分析功能。
## 概述
Debug 模块提供了一套完整的调试工具,包括日志系统和性能分析器。
## 模块内容
### 日志系统
| 组件 | 文件 | 描述 |
|------|------|------|
| [Logger](logger/logger.md) | `Logger.h` | 日志记录器 |
| [ILogSink](ilogsink/ilogsink.md) | `ILogSink.h` | 日志输出接口 |
| [ConsoleLogSink](consolelogsink/consolelogsink.md) | `ConsoleLogSink.h` | 控制台输出 |
| [FileLogSink](filelogsink/filelogsink.md) | `FileLogSink.h` | 文件输出 |
| [LogLevel](loglevel/loglevel.md) | `LogLevel.h` | 日志级别枚举 |
| [LogCategory](logcategory/logcategory.md) | `LogCategory.h` | 日志分类枚举 |
| [LogEntry](logentry/logentry.md) | `LogEntry.h` | 日志条目结构 |
### 性能分析
| 组件 | 文件 | 描述 |
|------|------|------|
| [Profiler](profiler/profiler.md) | `Profiler.h` | 性能分析器 |
## 日志级别
| 级别 | 描述 |
|------|------|
| `Verbose` | 详细调试信息 |
| `Debug` | 调试信息 |
| `Info` | 一般信息 |
| `Warning` | 警告信息 |
| `Error` | 错误信息 |
| `Fatal` | 致命错误 |
## 日志分类
| 分类 | 描述 |
|------|------|
| `General` | 通用 |
| `Rendering` | 渲染 |
| `Physics` | 物理 |
| `Audio` | 音频 |
| `Scripting` | 脚本 |
| `Network` | 网络 |
| `Memory` | 内存 |
| `Threading` | 线程 |
| `FileSystem` | 文件系统 |
| `Custom` | 自定义 |
## 使用示例
```cpp
#include <XCEngine/Debug/Debug.h>
// 初始化日志系统
Logger::Get().Initialize();
Logger::Get().AddSink(std::make_unique<ConsoleLogSink>());
Logger::Get().AddSink(std::make_unique<FileLogSink>("app.log"));
// 设置日志级别
Logger::Get().SetMinimumLevel(LogLevel::Debug);
// 记录日志
XE_LOG(LogCategory::Rendering, LogLevel::Info, "Render started");
// 使用宏记录日志
if (condition) {
XE_LOG(LogCategory::General, LogLevel::Error, "Something went wrong");
}
// 使用断言仅记录Fatal日志不会中断程序
XC_ASSERT(ptr != nullptr, "Pointer must not be null");
```
## 相关文档
- [Profiler](profiler/profiler.md) - 性能分析器