From 6d542f10466919e1c0eb34cc7898bbd926f9236e Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 4 Jan 2026 00:13:04 +0000 Subject: [PATCH] feat: Integrate logging system for improved error handling and debugging in application components --- src/app/sdl3_app_swapchain.cpp | 15 ++++++--------- src/script/audio_manager.cpp | 3 ++- src/script/gui_manager.cpp | 5 +++++ src/script/script_engine.cpp | 6 ++++++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/app/sdl3_app_swapchain.cpp b/src/app/sdl3_app_swapchain.cpp index af16b6c..3d3e182 100644 --- a/src/app/sdl3_app_swapchain.cpp +++ b/src/app/sdl3_app_swapchain.cpp @@ -24,22 +24,19 @@ void Sdl3App::CreateSwapChain() { // Validate window dimensions int windowWidth = 0, windowHeight = 0; SDL_GetWindowSize(window_, &windowWidth, &windowHeight); - std::cout << "Window size: " << windowWidth << "x" << windowHeight << "\n"; + LOG_INFO("Window size: " + std::to_string(windowWidth) + "x" + std::to_string(windowHeight)); if (windowWidth == 0 || windowHeight == 0) { + LOG_ERROR("Invalid window dimensions (" + std::to_string(windowWidth) + "x" + std::to_string(windowHeight) + "). Window may be minimized or invalid."); throw std::runtime_error("Invalid window dimensions (" + std::to_string(windowWidth) + "x" + std::to_string(windowHeight) + ").\n" + "Window may be minimized or invalid."); } - std::cout << "Surface capabilities:\n"; - std::cout << " Min extent: " << support.capabilities.minImageExtent.width - << "x" << support.capabilities.minImageExtent.height << "\n"; - std::cout << " Max extent: " << support.capabilities.maxImageExtent.width - << "x" << support.capabilities.maxImageExtent.height << "\n"; - std::cout << " Min images: " << support.capabilities.minImageCount << "\n"; - std::cout << " Max images: " << support.capabilities.maxImageCount << "\n"; - std::cout.flush(); + LOG_DEBUG("Surface capabilities - Min extent: " + std::to_string(support.capabilities.minImageExtent.width) + "x" + std::to_string(support.capabilities.minImageExtent.height) + + ", Max extent: " + std::to_string(support.capabilities.maxImageExtent.width) + "x" + std::to_string(support.capabilities.maxImageExtent.height) + + ", Min images: " + std::to_string(support.capabilities.minImageCount) + + ", Max images: " + std::to_string(support.capabilities.maxImageCount)); VkSurfaceFormatKHR surfaceFormat = ChooseSwapSurfaceFormat(support.formats); VkPresentModeKHR presentMode = ChooseSwapPresentMode(support.presentModes); diff --git a/src/script/audio_manager.cpp b/src/script/audio_manager.cpp index cf75af8..8bba762 100644 --- a/src/script/audio_manager.cpp +++ b/src/script/audio_manager.cpp @@ -1,5 +1,6 @@ #include "script/audio_manager.hpp" #include "app/audio_player.hpp" +#include "logging/logger.hpp" #include #include @@ -20,7 +21,7 @@ void AudioManager::SetAudioPlayer(app::AudioPlayer* audioPlayer) { try { ExecuteAudioCommand(audioPlayer_, command); } catch (const std::exception& exc) { - std::cerr << "AudioPlayer: " << exc.what() << '\n'; + LOG_ERROR("AudioPlayer command execution failed: " + std::string(exc.what())); } } pendingAudioCommands_.clear(); diff --git a/src/script/gui_manager.cpp b/src/script/gui_manager.cpp index 133edfd..fc38fa8 100644 --- a/src/script/gui_manager.cpp +++ b/src/script/gui_manager.cpp @@ -1,4 +1,5 @@ #include "script/gui_manager.hpp" +#include "logging/logger.hpp" #include @@ -34,10 +35,12 @@ std::vector GuiManager::LoadGuiCommands() { if (lua_pcall(L_, 0, 1, 0) != LUA_OK) { std::string message = GetLuaError(); lua_pop(L_, 1); + LOG_ERROR("Lua get_gui_commands failed: " + message); throw std::runtime_error("Lua get_gui_commands failed: " + message); } if (!lua_istable(L_, -1)) { lua_pop(L_, 1); + LOG_ERROR("'get_gui_commands' did not return a table"); throw std::runtime_error("'get_gui_commands' did not return a table"); } @@ -48,6 +51,7 @@ std::vector GuiManager::LoadGuiCommands() { lua_rawgeti(L_, -1, static_cast(i)); if (!lua_istable(L_, -1)) { lua_pop(L_, 1); + LOG_ERROR("GUI command at index " + std::to_string(i) + " is not a table"); throw std::runtime_error("GUI command at index " + std::to_string(i) + " is not a table"); } int commandIndex = lua_gettop(L_); @@ -55,6 +59,7 @@ std::vector GuiManager::LoadGuiCommands() { const char* typeName = lua_tostring(L_, -1); if (!typeName) { lua_pop(L_, 2); + LOG_ERROR("GUI command at index " + std::to_string(i) + " is missing a type"); throw std::runtime_error("GUI command at index " + std::to_string(i) + " is missing a type"); } GuiCommand command{}; diff --git a/src/script/script_engine.cpp b/src/script/script_engine.cpp index 78c961e..e630a4f 100644 --- a/src/script/script_engine.cpp +++ b/src/script/script_engine.cpp @@ -5,6 +5,7 @@ #include "script/audio_manager.hpp" #include "script/lua_bindings.hpp" #include "app/audio_player.hpp" +#include "logging/logger.hpp" #include @@ -25,9 +26,11 @@ ScriptEngine::ScriptEngine(const std::filesystem::path& scriptPath, bool debugEn guiManager_(std::make_unique(L_)), audioManager_(std::make_unique(scriptDirectory_)) { if (!L_) { + LOG_ERROR("Failed to create Lua state"); throw std::runtime_error("Failed to create Lua state"); } + LOG_DEBUG("Lua state created successfully"); luaL_openlibs(L_); LuaBindings::RegisterBindings(L_, this); @@ -57,8 +60,11 @@ ScriptEngine::ScriptEngine(const std::filesystem::path& scriptPath, bool debugEn lua_pop(L_, 1); lua_close(L_); L_ = nullptr; + LOG_ERROR("Failed to load Lua script: " + message); throw std::runtime_error("Failed to load Lua script: " + message); } + + LOG_INFO("Lua script loaded successfully: " + scriptPath.string()); } ScriptEngine::~ScriptEngine() {