mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat: Enhance logging in various controllers and services for better traceability
This commit is contained in:
@@ -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<controllers::LifecycleController>(registry_);
|
||||
applicationController_ = std::make_unique<controllers::ApplicationController>(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<events::EventBus, events::EventBus>();
|
||||
@@ -174,6 +178,8 @@ void ServiceBasedApp::RegisterServices() {
|
||||
|
||||
// Physics service
|
||||
registry_.RegisterService<services::IPhysicsService, services::impl::BulletPhysicsService>();
|
||||
|
||||
logging::Logger::GetInstance().Trace("ServiceBasedApp::RegisterServices: Exiting");
|
||||
}
|
||||
|
||||
} // namespace sdl3cpp::app
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<services::IGraphicsService>();
|
||||
@@ -26,7 +26,8 @@ void RenderController::RenderFrame(float time) {
|
||||
auto sceneService = registry_.GetService<services::ISceneService>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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<script::ScriptEngine>(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<script::SceneManager::SceneObject> 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<float, 16> ScriptService::ComputeModelMatrix(int functionRef, float time) {
|
||||
@@ -62,13 +68,15 @@ std::array<float, 16> ScriptService::ComputeModelMatrix(int functionRef, float t
|
||||
}
|
||||
|
||||
std::array<float, 16> 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<std::string, script::ShaderManager::ShaderPaths> ScriptService::LoadShaderPathsMap() {
|
||||
|
||||
Reference in New Issue
Block a user