feat: Integrate ILogger into SdlAudioService and PipelineService for enhanced logging

This commit is contained in:
2026-01-04 14:45:38 +00:00
parent 4d8bc2a457
commit f23c152928
4 changed files with 16 additions and 12 deletions

View File

@@ -194,7 +194,8 @@ void ServiceBasedApp::RegisterServices() {
// Pipeline service
registry_.RegisterService<services::IPipelineService, services::impl::PipelineService>(
registry_.GetService<services::IVulkanDeviceService>());
registry_.GetService<services::IVulkanDeviceService>(),
registry_.GetService<services::ILogger>());
// Buffer service
registry_.RegisterService<services::IBufferService, services::impl::BufferService>(

View File

@@ -57,6 +57,7 @@ void PipelineService::Cleanup() {
}
void PipelineService::Shutdown() noexcept {
logger_->TraceFunction(__func__);
Cleanup();
}
@@ -304,7 +305,7 @@ std::vector<char> PipelineService::ReadShaderFile(const std::string& path) {
file.read(buffer.data(), static_cast<std::streamsize>(fileSize));
file.close();
logging::Logger::GetInstance().Debug("Read shader file: " + path + " (" + std::to_string(fileSize) + " bytes)");
logger_->Debug("Read shader file: " + path + " (" + std::to_string(fileSize) + " bytes)");
return buffer;
}

View File

@@ -1,10 +1,10 @@
#include "sdl_audio_service.hpp"
#include "../../logging/logger.hpp"
#include <stdexcept>
namespace sdl3cpp::services::impl {
SdlAudioService::SdlAudioService() = default;
SdlAudioService::SdlAudioService(std::shared_ptr<ILogger> logger)
: logger_(logger) {}
SdlAudioService::~SdlAudioService() {
if (initialized_) {
@@ -13,7 +13,7 @@ SdlAudioService::~SdlAudioService() {
}
void SdlAudioService::Initialize() {
logging::TraceGuard trace;
logger_->TraceFunction(__func__);
if (initialized_) {
return;
@@ -22,11 +22,11 @@ void SdlAudioService::Initialize() {
audioPlayer_ = std::make_unique<app::AudioPlayer>();
initialized_ = true;
logging::Logger::GetInstance().Info("Audio service initialized");
logger_->Info("Audio service initialized");
}
void SdlAudioService::Shutdown() noexcept {
logging::TraceGuard trace;
logger_->TraceFunction(__func__);
if (!initialized_) {
return;
@@ -35,11 +35,11 @@ void SdlAudioService::Shutdown() noexcept {
audioPlayer_.reset();
initialized_ = false;
logging::Logger::GetInstance().Info("Audio service shutdown");
logger_->Info("Audio service shutdown");
}
void SdlAudioService::PlayBackground(const std::filesystem::path& path, bool loop) {
logging::TraceGuard trace;
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
throw std::runtime_error("Audio service not initialized");
@@ -49,7 +49,7 @@ void SdlAudioService::PlayBackground(const std::filesystem::path& path, bool loo
}
void SdlAudioService::PlayEffect(const std::filesystem::path& path, bool loop) {
logging::TraceGuard trace;
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
throw std::runtime_error("Audio service not initialized");
@@ -59,7 +59,7 @@ void SdlAudioService::PlayEffect(const std::filesystem::path& path, bool loop) {
}
void SdlAudioService::StopBackground() {
logging::TraceGuard trace;
logger_->TraceFunction(__func__);
if (!audioPlayer_) {
return;

View File

@@ -1,6 +1,7 @@
#pragma once
#include "../interfaces/i_audio_service.hpp"
#include "../interfaces/i_logger.hpp"
#include "../../app/audio_player.hpp"
#include "../../di/lifecycle.hpp"
#include <memory>
@@ -17,7 +18,7 @@ class SdlAudioService : public IAudioService,
public di::IInitializable,
public di::IShutdownable {
public:
SdlAudioService();
explicit SdlAudioService(std::shared_ptr<ILogger> logger);
~SdlAudioService() override;
// IAudioService interface
@@ -34,6 +35,7 @@ public:
bool IsBackgroundPlaying() const override;
private:
std::shared_ptr<ILogger> logger_;
std::unique_ptr<app::AudioPlayer> audioPlayer_;
float volume_ = 1.0f;
bool initialized_ = false;