...
This commit is contained in:
151
net/adc_netserver_spdlog.h
Normal file
151
net/adc_netserver_spdlog.h
Normal file
@@ -0,0 +1,151 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
|
||||
ABSTRACT DEVICE COMPONENTS LIBRARY
|
||||
|
||||
spdlog-library extensions
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifdef USE_SPDLOG_LIBRARY
|
||||
|
||||
#include <spdlog/logger.h>
|
||||
|
||||
#include "../common/adc_traits.h"
|
||||
#include "adc_netserver.h"
|
||||
|
||||
namespace adc
|
||||
{
|
||||
|
||||
template <traits::adc_netserver_session_c SessionT>
|
||||
class AdcNetServerSessionSpdlogDecorator : public SessionT
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<spdlog::logger> _logger;
|
||||
|
||||
void* _thisAddress;
|
||||
std::string _sessionID;
|
||||
|
||||
public:
|
||||
// using SessionT::sessionIdent;
|
||||
using typename SessionT::session_ident_t;
|
||||
|
||||
static_assert(traits::formattable<session_ident_t>, "NETWORK SESSION IDENT TYPE MUST BE A FORMATTABLE ONE!!!");
|
||||
|
||||
template <typename... ImplCtorArgTs>
|
||||
AdcNetServerSessionSpdlogDecorator(std::shared_ptr<spdlog::logger> logger, ImplCtorArgTs&&... ctor_args)
|
||||
: SessionT(std::forward<ImplCtorArgTs>(ctor_args)...),
|
||||
_logger(logger),
|
||||
_thisAddress((void*)std::addressof(this))
|
||||
{
|
||||
fmt::format_to(std::back_inserter(_sessionID), "{}", SessionT::sessionIdent());
|
||||
|
||||
_logger->trace("Call AdcNetServerSessionSpdlogDecorator::AdcNetServerSessionSpdlogDecorator (this: {})",
|
||||
_thisAddress);
|
||||
|
||||
_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()));
|
||||
}
|
||||
|
||||
virtual ~AdcNetServerSessionSpdlogDecorator()
|
||||
{
|
||||
_logger->trace("Call AdcNetServerSessionSpdlogDecorator::~AdcNetServerSessionSpdlogDecorator (this: {})",
|
||||
_thisAddress);
|
||||
|
||||
_logger->debug("Deleting network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress);
|
||||
|
||||
_logger->flush();
|
||||
};
|
||||
|
||||
virtual session_ident_t sessionIdent() const override
|
||||
{
|
||||
_logger->trace("Call AdcNetServerSessionSpdlogDecorator::sessionIdent (this: {})", _thisAddress);
|
||||
|
||||
return SessionT::sessionIdent();
|
||||
};
|
||||
|
||||
virtual void start() override
|
||||
{
|
||||
_logger->trace("Call AdcNetServerSessionSpdlogDecorator::start (this: {})", _thisAddress);
|
||||
|
||||
_logger->info("Starting network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress);
|
||||
|
||||
SessionT::start();
|
||||
};
|
||||
|
||||
virtual void stop() override
|
||||
{
|
||||
_logger->trace("Call AdcNetServerSessionSpdlogDecorator::stop (this: {})", _thisAddress);
|
||||
|
||||
_logger->info("Stopping network server session with ID = [{}] (ADDR = {})", _sessionID, _thisAddress);
|
||||
|
||||
SessionT::stop();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <traits::adc_netserver_c ServerT>
|
||||
class AdcNetServerSpdlogDecorator : public ServerT
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<spdlog::logger> _logger;
|
||||
|
||||
void* _thisAddress;
|
||||
std::string _serverID;
|
||||
|
||||
public:
|
||||
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))
|
||||
{
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
virtual ~AdcNetServerSpdlogDecorator()
|
||||
{
|
||||
_logger->trace("Call AdcNetServerSpdlogDecorator::~AdcNetServerSpdlogDecorator (this: {})", _thisAddress);
|
||||
|
||||
_logger->debug("Deleting network server with ID = [{}] (ADDR = {})", _serverID, _thisAddress);
|
||||
|
||||
_logger->flush();
|
||||
}
|
||||
|
||||
|
||||
virtual server_ident_t serverIdent() const
|
||||
{
|
||||
//
|
||||
return ServerT::serverIdent();
|
||||
}
|
||||
|
||||
virtual void start()
|
||||
{
|
||||
_logger->trace("Call AdcNetServerSpdlogDecorator::start (this: {})", _thisAddress);
|
||||
|
||||
_logger->info("Starting network server with ID = [{}] (ADDR = {})", _serverID, _thisAddress);
|
||||
|
||||
ServerT::start();
|
||||
};
|
||||
|
||||
virtual void stop()
|
||||
{
|
||||
//
|
||||
ServerT::stop();
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace adc
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user