feat: 实现日志与调试系统(Debug模块)

- LogLevel: 日志级别枚举 (Verbose, Debug, Info, Warning, Error, Fatal)
- LogCategory: 日志分类 (General, Rendering, Physics, Memory, Threading等)
- ILogSink: 日志输出接口
- ConsoleLogSink: 控制台输出, 支持Windows颜色
- FileLogSink: 文件日志输出
- FileWriter: 文件写入器
- Logger: 日志管理器, 支持多sink, 分类控制
- Profiler: 性能分析器
- 单元测试覆盖
This commit is contained in:
2026-03-13 20:53:57 +08:00
parent dc9b0751cb
commit 83fd517974
22 changed files with 780 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
#include "Debug/FileLogSink.h"
#include <ctime>
namespace XCEngine {
namespace Debug {
FileLogSink::FileLogSink(const Containers::String& filePath)
: m_filePath(filePath) {
m_writer.Open(filePath.CStr(), true);
}
FileLogSink::~FileLogSink() {
m_writer.Close();
}
void FileLogSink::Log(const LogEntry& entry) {
if (!m_writer.IsOpen()) {
return;
}
char timestamp[32];
std::time_t time = static_cast<std::time_t>(entry.timestamp);
std::strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", std::localtime(&time));
char buffer[1024];
std::snprintf(buffer, sizeof(buffer), "[%s] [%s] [%s] %s\n",
timestamp,
LogLevelToString(entry.level),
LogCategoryToString(entry.category),
entry.message.CStr());
m_writer.Write(buffer, std::strlen(buffer));
}
void FileLogSink::Flush() {
m_writer.Flush();
}
} // namespace Debug
} // namespace XCEngine