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; }