feat: 集成engine日志系统到D3D12测试程序\n- FileLogSink每次写入后刷新\n- main.cpp使用Logger输出日志
This commit is contained in:
@@ -30,6 +30,7 @@ void FileLogSink::Log(const LogEntry& entry) {
|
||||
entry.message.CStr());
|
||||
|
||||
m_writer.Write(buffer, std::strlen(buffer));
|
||||
m_writer.Flush();
|
||||
}
|
||||
|
||||
void FileLogSink::Flush() {
|
||||
|
||||
@@ -18,8 +18,12 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
||||
#include "XCEngine/Debug/Logger.h"
|
||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||
#include "XCEngine/Debug/FileLogSink.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
using namespace XCEngine::Debug;
|
||||
|
||||
#pragma comment(lib,"d3d12.lib")
|
||||
#pragma comment(lib,"dxgi.lib")
|
||||
@@ -29,17 +33,22 @@ using namespace XCEngine::RHI;
|
||||
static FILE* gLogFile = nullptr;
|
||||
|
||||
void Log(const char* format, ...) {
|
||||
char buffer[1024];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
|
||||
vprintf(format, args);
|
||||
|
||||
if (gLogFile) {
|
||||
va_start(args, format);
|
||||
vfprintf(gLogFile, format, args);
|
||||
va_end(args);
|
||||
fflush(gLogFile);
|
||||
}
|
||||
|
||||
Logger::Get().Debug(LogCategory::General, buffer);
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
@@ -959,6 +968,10 @@ LRESULT CALLBACK WindowProc(HWND inHWND, UINT inMSG, WPARAM inWParam, LPARAM inL
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int inShowCmd) {
|
||||
fopen_s(&gLogFile, "D3D12_log.txt", "w");
|
||||
|
||||
Logger::Get().AddSink(std::make_unique<FileLogSink>("D3D12_engine_log.txt"));
|
||||
Logger::Get().SetMinimumLevel(LogLevel::Debug);
|
||||
Logger::Get().Info(LogCategory::General, "Engine Logger initialized");
|
||||
|
||||
AllocConsole();
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
Log("[DEBUG] D3D12 Test Application Started\n");
|
||||
@@ -1142,8 +1155,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gLogFile) {
|
||||
if (gLogFile) {
|
||||
fclose(gLogFile);
|
||||
}
|
||||
Logger::Get().Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user