11#ifndef CPPTRAIL_BASE_LOGGER_H
12#define CPPTRAIL_BASE_LOGGER_H
27 template<
typename char_t>
39#if __cplusplus >= 201703L
97#if __cplusplus >= 202002L
120 template<
typename char_t>
132 : m_pLogger(std::move(pLogger)) {
146 if (this->m_pLogger && this->m_pLogger.use_count() == 1) {
147 this->m_pLogger->stop();
148 this->m_pLogger->join();
175#if __cplusplus >= 201703L
187 if (this->m_pLogger) this->m_pLogger->start();
196 if (this->m_pLogger) this->m_pLogger->stop();
206 if (this->m_pLogger) this->m_pLogger->signalStop();
216 if (this->m_pLogger) this->m_pLogger->join();
224 if (this->m_pLogger)
return this->m_pLogger->status();
237 if (this->m_pLogger) this->m_pLogger->log(std::move(oMessage));
249 tgetName<char_t>(nLevel), std::move(sMessage)
261 std::move(sLevel), std::move(sMessage)
335#if __cplusplus >= 201703L
448 template<typename T = char_t, typename std::enable_if<std::is_same<T, char>::value,
int>::type = 0>
461 template<typename T = char_t, typename std::enable_if<std::is_same<T, char>::value,
int>::type = 0>
474 template<typename T = char_t, typename std::enable_if<std::is_same<T, char>::value,
int>::type = 0>
483 std::shared_ptr<BasicLoggerImpl<char_t> > m_pLogger;
497#if __cplusplus >= 202002L
Abstract template interface defining the mandatory contract for all loggers.
Definition base_logger.h:28
virtual void join()=0
Waits for the asynchronous end of the shutdown sequence.
virtual void start()=0
Synchronously starts the logger service.
virtual void signalStop()=0
Asynchronously signals the logger to initiate a shutdown sequence.
std::basic_string_view< char_type > string_view_type
Alias for the basic_string_view type associated with this logger's encoding.
Definition base_logger.h:41
char_t char_type
Alias for the underlying character type used by this logger.
Definition base_logger.h:31
virtual ~BasicLoggerImpl()=default
Virtual destructor to ensure proper cleanup of derived logger resources.
virtual Status status()=0
Retrieves the current operational health and state of the logger.
virtual void log(message_type oMessage)=0
Primary interface for submitting a log record.
std::basic_string< char_type > string_type
Alias for the basic_string type associated with this logger's encoding.
Definition base_logger.h:34
virtual void stop()=0
Synchronously stops the logger service.
A high-level handle for logging operations.
Definition base_logger.h:121
BasicLogger & warning(const char_t *sMsg)
Warning wrapper for string litterals.
Definition base_logger.h:423
BasicLogger & log(const Level nLevel, string_type sMessage)
Logs a message with a specific severity level.
Definition base_logger.h:247
BasicLogger & info(string_view_type sMsg)
Info wrapper for string views.
Definition base_logger.h:370
void start()
Starts the underlying logging service.
Definition base_logger.h:186
void stop()
Performs a synchronous shutdown of the logger.
Definition base_logger.h:195
BasicLogger & fatal(string_view_type sMsg)
Fatal wrapper for string views.
Definition base_logger.h:380
BasicLogger & operator=(const BasicLogger &pLogger)=default
Assignment operator.
BasicLogger & info(string_type sMessage)
Submits an INFO level log message.
Definition base_logger.h:297
BasicLogger(nullptr_t)=delete
Prevents construction from a null pointer.
BasicLogger & warning(string_type sMessage)
Submits a WARNING level log message.
Definition base_logger.h:311
BasicLogger & fatal(const char_t *sMsg)
Fatal wrapper for string litterals.
Definition base_logger.h:429
BasicLogger & success(string_type sMessage)
Submits a SUCCESS level log message.
Definition base_logger.h:276
BasicLogger & critical(string_view_type sMsg)
Critical wrapper for string views.
Definition base_logger.h:378
BasicLogger & message(const char_t *sMsg)
Message wrapper for string litterals.
Definition base_logger.h:421
BasicLogger & trace(const char_t *sMsg)
Trace wrapper for string litterals.
Definition base_logger.h:415
BasicLogger & success(string_view_type sMsg)
Success wrapper for string views.
Definition base_logger.h:364
BasicLogger & log(const Level nLevel, const std::exception &oException)
Logs an exception with a specific severity level.
Definition base_logger.h:462
BasicLogger & success(const char_t *sMsg)
Success wrapper for string litterals.
Definition base_logger.h:413
BasicLogger & critical(const char_t *sMsg)
Critical wrapper for string litterals.
Definition base_logger.h:427
BasicLogger & info(const char_t *sMsg)
Info wrapper for string litterals.
Definition base_logger.h:419
BasicLogger & fatal(string_type sMessage)
Submits a FATAL level log message.
Definition base_logger.h:332
BasicLogger & message(string_type sMessage)
Submits a MESSAGE level log message.
Definition base_logger.h:304
~BasicLogger()
Destructor that ensures a graceful shutdown of the logger.
Definition base_logger.h:145
BasicLogger & critical(string_type sMessage)
Submits a CRITICAL level log message.
Definition base_logger.h:325
typename BasicLoggerImpl< char_t >::string_view_type string_view_type
Alias for the basic_string_view type associated with this logger's encoding.
Definition base_logger.h:177
BasicLogger & log(string_type sLevel, const char_t *sMessage)
Logs a message view with a custom string level.
Definition base_logger.h:405
BasicLogger & message(string_view_type sMsg)
Message wrapper for string views.
Definition base_logger.h:372
BasicLogger(const BasicLogger &pLogger)=default
Copy constructor (defaults to shared ownership).
typename BasicLoggerImpl< char_t >::char_type char_type
Alias for the underlying character type used by this logger.
Definition base_logger.h:167
BasicLogger(std::shared_ptr< BasicLoggerImpl< char_t > > pLogger)
Protected constructor for derived factories.
Definition base_logger.h:131
BasicLogger & log(const Level nLevel, string_view_type sMessage)
Logs a message view with a specific severity level.
Definition base_logger.h:346
BasicLogger & trace(string_view_type sMsg)
Trace wrapper for string views.
Definition base_logger.h:366
BasicLogger & log(string_type sLevel, string_type sMessage)
Logs a message with a custom string-based level.
Definition base_logger.h:259
typename BasicLoggerImpl< char_t >::message_type message_type
Alias for the BasicMessage type associated to the logger.
Definition base_logger.h:173
Status status()
Retrieves the current operational status of the logger.
Definition base_logger.h:223
BasicLogger & trace(string_type sMessage)
Submits a TRACE level log message.
Definition base_logger.h:283
BasicLogger & error(const char_t *sMsg)
Error wrapper for string litterals.
Definition base_logger.h:425
typename BasicLoggerImpl< char_t >::string_type string_type
Alias for the basic_string type associated with this logger's encoding.
Definition base_logger.h:170
BasicLogger & error(string_view_type sMsg)
Error wrapper for string views.
Definition base_logger.h:376
void signalStop()
Initiates an asynchronous shutdown request.
Definition base_logger.h:205
BasicLogger & log(const std::exception &oException)
Logs an exception with the default ERROR level.
Definition base_logger.h:449
BasicLogger & error(string_type sMessage)
Submits an ERROR level log message.
Definition base_logger.h:318
BasicLogger & log(const Level nLevel, const char_t *sMessage)
Logs a message view with a specific severity level.
Definition base_logger.h:395
BasicLogger & warning(string_view_type sMsg)
Warning wrapper for string views.
Definition base_logger.h:374
BasicLogger(BasicLogger &&pLogger)=default
Move constructor.
BasicLogger & log(string_type sLevel, const std::exception &oException)
Logs an exception with a custom string level.
Definition base_logger.h:475
BasicLogger & debug(const char_t *sMsg)
Debug wrapper for string litterals.
Definition base_logger.h:417
BasicLogger & debug(string_type sMessage)
Submits a DEBUG level log message.
Definition base_logger.h:290
void join()
Blocks until the asynchronous shutdown sequence is complete.
Definition base_logger.h:215
BasicLogger & log(message_type oMessage)
Submits a pre-constructed message object to the logger.
Definition base_logger.h:236
BasicLogger & operator=(BasicLogger &&pLogger)=default
Assignment operator.
BasicLogger & debug(string_view_type sMsg)
Debug wrapper for string views.
Definition base_logger.h:368
BasicLogger & log(string_type sLevel, string_view_type sMessage)
Logs a message view with a custom string level.
Definition base_logger.h:356
Container for log message implementations.
Definition message.h:76
A standard string-based log message.
Definition message.h:169
Root namespace for the CppTrail logging library.
Definition async_logger.h:24
Level
Severity levels for log entries.
Definition def.h:42
@ WARNING
Indications of potential issues or non-critical failures.
@ FATAL
Terminal errors that require immediate application termination.
@ TRACE
Extremely fine-grained diagnostic events (wire-level).
@ INFO
General operational messages about application progress.
@ MESSAGE
High-level communication or protocol-specific messages.
@ CRITICAL
Severe failures that may lead to localized component shutdown.
@ ERROR
Significant issues that require attention but allow continued execution.
@ SUCCESS
Positive confirmation of a successful operation.
@ DEBUG
Information useful for application debugging.
Status
Represents the current operational state of a Logger implementation.
Definition def.h:31