From d2934ebc8d71d3c8f209266044cbf91ca9dc0a72 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 4 Jan 2026 14:12:38 +0000 Subject: [PATCH] feat: Enhance logging in various controllers and services for better traceability --- src/app/service_based_app.cpp | 26 +++++++++++++--------- src/controllers/application_controller.cpp | 13 ++++++----- src/controllers/lifecycle_controller.cpp | 18 ++++++++------- src/controllers/render_controller.cpp | 11 +++++---- src/services/impl/script_service.cpp | 24 +++++++++++++------- 5 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/app/service_based_app.cpp b/src/app/service_based_app.cpp index 03cd8b6..aa3d30f 100644 --- a/src/app/service_based_app.cpp +++ b/src/app/service_based_app.cpp @@ -23,21 +23,21 @@ namespace sdl3cpp::app { ServiceBasedApp::ServiceBasedApp(const std::filesystem::path& scriptPath) : scriptPath_(scriptPath) { - logging::Logger::GetInstance().Info("ServiceBasedApp constructor starting"); + logging::Logger::GetInstance().Info("ServiceBasedApp::ServiceBasedApp: constructor starting"); try { - logging::Logger::GetInstance().Info("Setting up SDL"); + logging::Logger::GetInstance().Info("ServiceBasedApp::ServiceBasedApp: Setting up SDL"); SetupSDL(); - logging::Logger::GetInstance().Info("Registering services"); + logging::Logger::GetInstance().Info("ServiceBasedApp::ServiceBasedApp: Registering services"); RegisterServices(); - logging::Logger::GetInstance().Info("Creating controllers"); + logging::Logger::GetInstance().Info("ServiceBasedApp::ServiceBasedApp: Creating controllers"); lifecycleController_ = std::make_unique(registry_); applicationController_ = std::make_unique(registry_); - logging::Logger::GetInstance().Info("ServiceBasedApp constructor completed"); + logging::Logger::GetInstance().Info("ServiceBasedApp::ServiceBasedApp: constructor completed"); } catch (const std::exception& e) { - logging::Logger::GetInstance().Error("Failed to initialize ServiceBasedApp: " + std::string(e.what())); + logging::Logger::GetInstance().Error("ServiceBasedApp::ServiceBasedApp: Failed to initialize ServiceBasedApp: " + std::string(e.what())); throw; } } @@ -50,7 +50,7 @@ ServiceBasedApp::~ServiceBasedApp() { } void ServiceBasedApp::Run() { - logging::TraceGuard trace("ServiceBasedApp::Run"); + logging::Logger::GetInstance().Trace("ServiceBasedApp::Run: Entering"); try { // Initialize all services @@ -97,21 +97,25 @@ void ServiceBasedApp::Run() { // Shutdown all services lifecycleController_->ShutdownAll(); + logging::Logger::GetInstance().Trace("ServiceBasedApp::Run: Exiting"); + } catch (const std::exception& e) { - logging::Logger::GetInstance().Error("Application error: " + std::string(e.what())); + logging::Logger::GetInstance().Error("ServiceBasedApp::Run: Application error: " + std::string(e.what())); throw; } } void ServiceBasedApp::SetupSDL() { - logging::TraceGuard trace("ServiceBasedApp::SetupSDL"); + logging::Logger::GetInstance().Trace("ServiceBasedApp::SetupSDL: Entering"); // SDL initialization is handled by the window service // Don't initialize SDL here to avoid double initialization + + logging::Logger::GetInstance().Trace("ServiceBasedApp::SetupSDL: Exiting"); } void ServiceBasedApp::RegisterServices() { - logging::TraceGuard trace("ServiceBasedApp::RegisterServices"); + logging::Logger::GetInstance().Trace("ServiceBasedApp::RegisterServices: Entering"); // Event bus (needed by window service) registry_.RegisterService(); @@ -174,6 +178,8 @@ void ServiceBasedApp::RegisterServices() { // Physics service registry_.RegisterService(); + + logging::Logger::GetInstance().Trace("ServiceBasedApp::RegisterServices: Exiting"); } } // namespace sdl3cpp::app \ No newline at end of file diff --git a/src/controllers/application_controller.cpp b/src/controllers/application_controller.cpp index b9f19a5..b86994e 100644 --- a/src/controllers/application_controller.cpp +++ b/src/controllers/application_controller.cpp @@ -13,17 +13,17 @@ namespace sdl3cpp::controllers { ApplicationController::ApplicationController(di::ServiceRegistry& registry) : registry_(registry), running_(false) { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("ApplicationController::ApplicationController: Created"); } ApplicationController::~ApplicationController() { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("ApplicationController::~ApplicationController: Destroyed"); } void ApplicationController::Run() { - logging::Logger::GetInstance().Info("ApplicationController::Run starting"); - logging::TraceGuard trace; - logging::Logger::GetInstance().Info("Application starting main loop"); + logging::Logger::GetInstance().Trace("ApplicationController::Run: Entering"); + logging::Logger::GetInstance().Info("ApplicationController::Run: ApplicationController::Run starting"); + logging::Logger::GetInstance().Info("ApplicationController::Run: Application starting main loop"); running_ = true; auto lastTime = std::chrono::high_resolution_clock::now(); @@ -47,7 +47,8 @@ void ApplicationController::Run() { ProcessFrame(deltaTime); } - logging::Logger::GetInstance().Info("Application exiting main loop"); + logging::Logger::GetInstance().Info("ApplicationController::Run: Application exiting main loop"); + logging::Logger::GetInstance().Trace("ApplicationController::Run: Exiting"); } void ApplicationController::HandleEvents() { diff --git a/src/controllers/lifecycle_controller.cpp b/src/controllers/lifecycle_controller.cpp index e39cc16..51c74f8 100644 --- a/src/controllers/lifecycle_controller.cpp +++ b/src/controllers/lifecycle_controller.cpp @@ -5,31 +5,33 @@ namespace sdl3cpp::controllers { LifecycleController::LifecycleController(di::ServiceRegistry& registry) : registry_(registry) { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("LifecycleController::LifecycleController: Created"); } LifecycleController::~LifecycleController() { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("LifecycleController::~LifecycleController: Destroyed"); } void LifecycleController::InitializeAll() { - logging::TraceGuard trace; - logging::Logger::GetInstance().Info("Initializing all services"); + logging::Logger::GetInstance().Trace("LifecycleController::InitializeAll: Entering"); + logging::Logger::GetInstance().Info("LifecycleController::InitializeAll: Initializing all services"); // ServiceRegistry handles initialization order based on dependencies registry_.InitializeAll(); - logging::Logger::GetInstance().Info("All services initialized"); + logging::Logger::GetInstance().Info("LifecycleController::InitializeAll: All services initialized"); + logging::Logger::GetInstance().Trace("LifecycleController::InitializeAll: Exiting"); } void LifecycleController::ShutdownAll() noexcept { - logging::TraceGuard trace; - logging::Logger::GetInstance().Info("Shutting down all services"); + logging::Logger::GetInstance().Trace("LifecycleController::ShutdownAll: Entering"); + logging::Logger::GetInstance().Info("LifecycleController::ShutdownAll: Shutting down all services"); // ServiceRegistry handles shutdown in reverse dependency order registry_.ShutdownAll(); - logging::Logger::GetInstance().Info("All services shutdown"); + logging::Logger::GetInstance().Info("LifecycleController::ShutdownAll: All services shutdown"); + logging::Logger::GetInstance().Trace("LifecycleController::ShutdownAll: Exiting"); } } // namespace sdl3cpp::controllers diff --git a/src/controllers/render_controller.cpp b/src/controllers/render_controller.cpp index 80b4ab8..2b269e7 100644 --- a/src/controllers/render_controller.cpp +++ b/src/controllers/render_controller.cpp @@ -9,15 +9,15 @@ namespace sdl3cpp::controllers { RenderController::RenderController(di::ServiceRegistry& registry) : registry_(registry) { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("RenderController::RenderController: Created"); } RenderController::~RenderController() { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("RenderController::~RenderController: Destroyed"); } void RenderController::RenderFrame(float time) { - logging::TraceGuard trace; + logging::Logger::GetInstance().Trace("RenderController::RenderFrame: Entering"); // Get required services auto graphicsService = registry_.GetService(); @@ -26,7 +26,8 @@ void RenderController::RenderFrame(float time) { auto sceneService = registry_.GetService(); if (!graphicsService) { - logging::Logger::GetInstance().Error("Graphics service not available"); + logging::Logger::GetInstance().Error("RenderController::RenderFrame: Graphics service not available"); + logging::Logger::GetInstance().Trace("RenderController::RenderFrame: Exiting"); return; } @@ -59,6 +60,8 @@ void RenderController::RenderFrame(float time) { // End frame and present graphicsService->EndFrame(); + + logging::Logger::GetInstance().Trace("RenderController::RenderFrame: Exiting"); } } // namespace sdl3cpp::controllers diff --git a/src/services/impl/script_service.cpp b/src/services/impl/script_service.cpp index 417de8f..9e1506f 100644 --- a/src/services/impl/script_service.cpp +++ b/src/services/impl/script_service.cpp @@ -7,18 +7,18 @@ namespace sdl3cpp::services::impl { ScriptService::ScriptService(const std::filesystem::path& scriptPath) : scriptPath_(scriptPath) { - logging::TraceGuard trace("ScriptService::ScriptService"); + logging::Logger::GetInstance().Trace("ScriptService::ScriptService: Created"); } ScriptService::~ScriptService() { - logging::TraceGuard trace("ScriptService::~ScriptService"); + logging::Logger::GetInstance().Trace("ScriptService::~ScriptService: Destroyed"); if (initialized_) { Shutdown(); } } void ScriptService::Initialize() { - logging::TraceGuard trace("ScriptService::Initialize"); + logging::Logger::GetInstance().Trace("ScriptService::Initialize: Entering"); if (initialized_) { throw std::runtime_error("Script service already initialized"); @@ -27,28 +27,34 @@ void ScriptService::Initialize() { try { scriptEngine_ = std::make_unique(scriptPath_); initialized_ = true; + logging::Logger::GetInstance().Trace("ScriptService::Initialize: Exiting"); } catch (const std::exception& e) { + logging::Logger::GetInstance().Trace("ScriptService::Initialize: Exiting with error"); throw std::runtime_error(std::string("Failed to initialize script engine: ") + e.what()); } } void ScriptService::Shutdown() noexcept { - logging::TraceGuard trace("ScriptService::Shutdown"); + logging::Logger::GetInstance().Trace("ScriptService::Shutdown: Entering"); if (scriptEngine_) { scriptEngine_.reset(); } initialized_ = false; + + logging::Logger::GetInstance().Trace("ScriptService::Shutdown: Exiting"); } std::vector ScriptService::LoadSceneObjects() { - logging::TraceGuard trace("ScriptService::LoadSceneObjects"); + logging::Logger::GetInstance().Trace("ScriptService::LoadSceneObjects: Entering"); if (!initialized_) { throw std::runtime_error("Script service not initialized"); } - return scriptEngine_->LoadSceneObjects(); + auto result = scriptEngine_->LoadSceneObjects(); + logging::Logger::GetInstance().Trace("ScriptService::LoadSceneObjects: Exiting"); + return result; } std::array ScriptService::ComputeModelMatrix(int functionRef, float time) { @@ -62,13 +68,15 @@ std::array ScriptService::ComputeModelMatrix(int functionRef, float t } std::array ScriptService::GetViewProjectionMatrix(float aspect) { - logging::TraceGuard trace("ScriptService::GetViewProjectionMatrix"); + logging::Logger::GetInstance().Trace("ScriptService::GetViewProjectionMatrix: Entering"); if (!initialized_) { throw std::runtime_error("Script service not initialized"); } - return scriptEngine_->GetViewProjectionMatrix(aspect); + auto result = scriptEngine_->GetViewProjectionMatrix(aspect); + logging::Logger::GetInstance().Trace("ScriptService::GetViewProjectionMatrix: Exiting"); + return result; } std::unordered_map ScriptService::LoadShaderPathsMap() {