From 02811a92b5ea0d47deaadc554ae889444e80daa5 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 9 Jun 2024 23:41:44 +0300 Subject: [PATCH] ... --- net/adc_netserver_spdlog.h | 72 +++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/net/adc_netserver_spdlog.h b/net/adc_netserver_spdlog.h index 941c9bc..9300435 100644 --- a/net/adc_netserver_spdlog.h +++ b/net/adc_netserver_spdlog.h @@ -20,15 +20,18 @@ namespace adc { template -class AdcNetServerSessionSpdlogDecorator : public SessionT +class AdcNetServerSessionSpdlogDecorator : public AdcSpdlogGenericMarkDecorator { protected: - std::shared_ptr _logger; + using base_t = AdcSpdlogGenericMarkDecorator; - void* _thisAddress; std::string _sessionID; public: + using base_t::logDebug; + using base_t::logInfo; + using base_t::logMethodCalling; + // using SessionT::sessionIdent; using typename SessionT::session_ident_t; @@ -36,63 +39,62 @@ public: template AdcNetServerSessionSpdlogDecorator(std::shared_ptr logger, ImplCtorArgTs&&... ctor_args) - : SessionT(std::forward(ctor_args)...), - _logger(logger), - _thisAddress((void*)std::addressof(this)) + : base_t("ADC NETSERVER SESSION", logger, std::forward(ctor_args)...) { + logMethodCalling(__PRETTY_FUNCTION__); + fmt::format_to(std::back_inserter(_sessionID), "{}", SessionT::sessionIdent()); - _logger->trace("Call AdcNetServerSessionSpdlogDecorator::AdcNetServerSessionSpdlogDecorator (this: {})", - _thisAddress); + this->setPattern(base_t::constructPattern(_sessionID)); - _logger->debug("Creating network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress); - _logger->debug("use logger with name [{}] and level [{}]", _logger->name(), - spdlog::level::to_string_view(_logger->level())); + logDebug("Creating network server session with ID = [{}] (ADDR = {})", _sessionID, this->_thisAddress); + logDebug("Use logger with ", this->loggerInfo()); } virtual ~AdcNetServerSessionSpdlogDecorator() { - _logger->trace("Call AdcNetServerSessionSpdlogDecorator::~AdcNetServerSessionSpdlogDecorator (this: {})", - _thisAddress); + logMethodCalling(__PRETTY_FUNCTION__); - _logger->debug("Deleting network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress); - - _logger->flush(); + logDebug("Deleting network server session with ID = [{}] (ADDR = {})", _sessionID, this->_thisAddress); }; virtual session_ident_t sessionIdent() const override { - _logger->trace("Call AdcNetServerSessionSpdlogDecorator::sessionIdent (this: {})", _thisAddress); + logMethodCalling(__PRETTY_FUNCTION__); return SessionT::sessionIdent(); }; virtual void start() override { - _logger->trace("Call AdcNetServerSessionSpdlogDecorator::start (this: {})", _thisAddress); + logMethodCalling(__PRETTY_FUNCTION__); - _logger->info("Starting network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress); + logInfo("Starting network server session with ID = [{}]", _sessionID); SessionT::start(); + + logInfo("Network server session [{}] is started", _sessionID); }; virtual void stop() override { - _logger->trace("Call AdcNetServerSessionSpdlogDecorator::stop (this: {})", _thisAddress); + logMethodCalling(__PRETTY_FUNCTION__); - _logger->info("Stopping network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress); + logInfo("Stopping network server session with ID = [{}]", _sessionID); SessionT::stop(); + + logInfo("Network server session [{}] is stopped", _sessionID); }; }; template -class AdcNetServerSpdlogDecorator : public AdcSpdlogGenericDecorator +class AdcNetServerSpdlogDecorator : public AdcSpdlogGenericMarkDecorator { protected: - using base_t = AdcSpdlogGenericDecorator; + using base_t = AdcSpdlogGenericMarkDecorator; std::string _serverID; @@ -106,19 +108,26 @@ public: using typename ServerT::server_ident_t; + static_assert(traits::formattable, "NETWORK SERVER IDENT TYPE MUST BE A FORMATTABLE ONE!!!"); + template AdcNetServerSpdlogDecorator(std::shared_ptr logger, ImplCtorArgTs&&... ctor_args) - : base_t(logger, std::forward(ctor_args)...) + : base_t("ADC NETSERVER", logger, std::forward(ctor_args)...) { + this->logMethodCalling(__PRETTY_FUNCTION__); + fmt::format_to(std::back_inserter(_serverID), "{}", ServerT::serverIdent()); + this->setPattern(base_t::constructPattern(_serverID)); + logDebug("Creating network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress); + logDebug("Use logger with ", this->loggerInfo()); } virtual ~AdcNetServerSpdlogDecorator() { - this->logMethodCalling(); + this->logMethodCalling(__PRETTY_FUNCTION__); logDebug("Deleting network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress); } @@ -126,26 +135,31 @@ public: virtual server_ident_t serverIdent() const { - // + this->logMethodCalling(__PRETTY_FUNCTION__); + return ServerT::serverIdent(); } virtual void start() { - this->logMethodCalling(); + this->logMethodCalling(__PRETTY_FUNCTION__); logInfo("Starting network server"); ServerT::start(); + + logInfo("Network server is started"); }; virtual void stop() { - this->logMethodCalling(); + this->logMethodCalling(__PRETTY_FUNCTION__); - logInfo("Stopping network server"); + logInfo("Stopping network server ..."); ServerT::stop(); + + logInfo("Network server is stopped"); }; };