58std::string
inline demangle(
const char* name) {
60 using deleter_t = void(*)(
void*);
61 std::unique_ptr<char, deleter_t> demangled(abi::__cxa_demangle(name,
nullptr,
nullptr, &status), std::free);
62 return (status == 0 && demangled) ? demangled.get() : name;
114template <
typename Derived>
134 explicit GBase(
const std::shared_ptr<GOptions>& gopt, std::string logger_name =
"") {
135 log = std::make_shared<GLogger>(gopt, getDerivedName(), logger_name);
156 explicit GBase(
const std::shared_ptr<GLogger>& logger) :
log(logger) {
231 [[nodiscard]] std::
string getDerivedName()
const {
return demangle(
typeid(Derived).name()); }
256 std::shared_ptr<GLogger>
log;
CRTP base class that provides logging facilities to the derived class.
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
Construct a base that creates (and owns) a logger for the derived instance.
GBase(const std::shared_ptr< GLogger > &logger)
Construct a base that reuses an existing logger.
GBase & operator=(const GBase &)=default
Copy assignment (shallow copy of the logger pointer).
virtual ~GBase()
Destructor that logs object destruction when a logger is available.
GBase(const GBase &)=default
Copy constructor (shallow copy of the logger pointer).
GBase(GBase &&) noexcept=default
Move constructor.
std::shared_ptr< GLogger > log
Shared logger used by the derived class for emitting messages.
void debug(debug_type type, Args &&... args) const
std::string demangle(const char *name)
Fallback demangle implementation for non-GNU toolchains.