From c6d7ef4c39b0b456252717e73db8ecd47b60f57d Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sun, 15 Mar 2026 14:25:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9B=86=E6=88=90engine=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=B3=BB=E7=BB=9F=E5=88=B0D3D12=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F\n-=20FileLogSink=E6=AF=8F=E6=AC=A1=E5=86=99?= =?UTF-8?q?=E5=85=A5=E5=90=8E=E5=88=B7=E6=96=B0\n-=20main.cpp=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Logger=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/src/Debug/FileLogSink.cpp | 1 + tests/D3D12/main.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/engine/src/Debug/FileLogSink.cpp b/engine/src/Debug/FileLogSink.cpp index 2f972e88..82a9ce1e 100644 --- a/engine/src/Debug/FileLogSink.cpp +++ b/engine/src/Debug/FileLogSink.cpp @@ -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() { diff --git a/tests/D3D12/main.cpp b/tests/D3D12/main.cpp index be44acc8..2f2fcff3 100644 --- a/tests/D3D12/main.cpp +++ b/tests/D3D12/main.cpp @@ -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("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; }