feat: Integrate logging system for improved error handling and debugging in application components

This commit is contained in:
2026-01-04 00:13:04 +00:00
parent 33ca375034
commit 6d542f1046
4 changed files with 19 additions and 10 deletions

View File

@@ -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);

View File

@@ -1,5 +1,6 @@
#include "script/audio_manager.hpp"
#include "app/audio_player.hpp"
#include "logging/logger.hpp"
#include <iostream>
#include <stdexcept>
@@ -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();

View File

@@ -1,4 +1,5 @@
#include "script/gui_manager.hpp"
#include "logging/logger.hpp"
#include <lua.hpp>
@@ -34,10 +35,12 @@ std::vector<GuiCommand> 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<GuiCommand> GuiManager::LoadGuiCommands() {
lua_rawgeti(L_, -1, static_cast<int>(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<GuiCommand> 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{};

View File

@@ -5,6 +5,7 @@
#include "script/audio_manager.hpp"
#include "script/lua_bindings.hpp"
#include "app/audio_player.hpp"
#include "logging/logger.hpp"
#include <lua.hpp>
@@ -25,9 +26,11 @@ ScriptEngine::ScriptEngine(const std::filesystem::path& scriptPath, bool debugEn
guiManager_(std::make_unique<GuiManager>(L_)),
audioManager_(std::make_unique<AudioManager>(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() {