This commit is contained in:
Timur A. Fatkhullin
2024-06-09 20:05:42 +03:00
parent a482a8dbc8
commit 8c1410ec90
3 changed files with 147 additions and 39 deletions

View File

@@ -11,9 +11,9 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
#ifdef USE_SPDLOG_LIBRARY
#include <spdlog/logger.h>
#include "../common/adc_spdlog.h"
#include "../common/adc_traits.h"
#include "adc_netserver.h"
namespace adc
@@ -89,38 +89,38 @@ public:
template <traits::adc_netserver_c ServerT>
class AdcNetServerSpdlogDecorator : public ServerT
class AdcNetServerSpdlogDecorator : public AdcSpdlogGenericDecorator<ServerT>
{
protected:
std::shared_ptr<spdlog::logger> _logger;
using base_t = AdcSpdlogGenericDecorator<ServerT>;
void* _thisAddress;
std::string _serverID;
public:
using base_t::logCritical;
using base_t::logDebug;
using base_t::logError;
using base_t::logInfo;
using base_t::logMsg;
using base_t::logWarn;
using typename ServerT::server_ident_t;
template <typename... ImplCtorArgTs>
AdcNetServerSpdlogDecorator(std::shared_ptr<spdlog::logger> logger, ImplCtorArgTs&&... ctor_args)
: ServerT(std::forward<ImplCtorArgTs>(ctor_args)...), _logger(logger), _thisAddress((void*)std::addressof(this))
: base_t(logger, std::forward<ImplCtorArgTs>(ctor_args)...)
{
fmt::format_to(std::back_inserter(_serverID), "{}", ServerT::serverIdent());
_logger->trace("Call AdcNetServerSpdlogDecorator::AdcNetServerSpdlogDecorator (this: {})", _thisAddress);
_logger->debug("Creating network server session with ID = [{}] (ADDR = {})", _serverID, _thisAddress);
_logger->debug("use logger with name [{}] and level [{}]", _logger->name(),
spdlog::level::to_string_view(_logger->level()));
logDebug("Creating network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress);
}
virtual ~AdcNetServerSpdlogDecorator()
{
_logger->trace("Call AdcNetServerSpdlogDecorator::~AdcNetServerSpdlogDecorator (this: {})", _thisAddress);
this->logMethodCalling();
_logger->debug("Deleting network server with ID = [{}] (ADDR = {})", _serverID, _thisAddress);
_logger->flush();
logDebug("Deleting network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress);
}
@@ -132,16 +132,19 @@ public:
virtual void start()
{
_logger->trace("Call AdcNetServerSpdlogDecorator::start (this: {})", _thisAddress);
this->logMethodCalling();
_logger->info("Starting network server with ID = [{}] (ADDR = {})", _serverID, _thisAddress);
logInfo("Starting network server");
ServerT::start();
};
virtual void stop()
{
//
this->logMethodCalling();
logInfo("Stopping network server");
ServerT::stop();
};
};