CppTrail
Loading...
Searching...
No Matches
CppTrail::BasicSyncLoggerImpl< char_t > Class Template Referenceabstract

A synchronous, thread-safe logger implementation template. This class ensures that every log call is processed immediately on the calling thread. Access to the 'work' function is protected by a mutex, making it safe for multi-threaded environments, though it may introduce latency in the calling thread. More...

#include <sync_logger.h>

Inheritance diagram for CppTrail::BasicSyncLoggerImpl< char_t >:
Collaboration diagram for CppTrail::BasicSyncLoggerImpl< char_t >:

Public Types

using char_type = typename BasicLoggerImpl< char_t >::char_type
 Alias for the underlying character type used by this logger.
 
using string_type = typename BasicLoggerImpl< char_t >::string_type
 Alias for the basic_string type associated with this logger's encoding.
 
using message_type = typename BasicLoggerImpl< char_t >::message_type
 Alias for the BasicMessage type associated to the logger.
 
- Public Types inherited from CppTrail::BasicLoggerImpl< char_t >
using char_type = char_t
 Alias for the underlying character type used by this logger.
 
using string_type = std::basic_string< char_type >
 Alias for the basic_string type associated with this logger's encoding.
 
using message_type = BasicMessage< char_type >
 Alias for the BasicMessage type associated to the logger.
 
using string_view_type = std::basic_string_view< char_type >
 Alias for the basic_string_view type associated with this logger's encoding.
 

Public Member Functions

void log (message_type oMessage) final
 Synchronously processes and records a log message.
 
void start () final
 Starts the logger service.
 
void stop () final
 Stops the logger service.
 
void signalStop () final
 Signals the logger to stop.
 
void join () override
 Waits for the asynchronous end of the shutdown sequence.
 
Status status () final
 Retrieves the current status of the service.
 
- Public Member Functions inherited from CppTrail::BasicLoggerImpl< char_t >
virtual ~BasicLoggerImpl ()=default
 Virtual destructor to ensure proper cleanup of derived logger resources.
 

Protected Member Functions

 ~BasicSyncLoggerImpl () override=default
 Destructor.
 
virtual void work (message_type oMessage)=0
 Abstract method where the actual logging I/O occurs.
 
Internal Service Interface

These methods must be implemented by derived classes to handle the specific backend lifecycle without worrying about locking.

virtual Status serviceStatus ()=0
 Non-locking call to get the current service status.
 
virtual void serviceStart ()=0
 Non-locking call to initiate service startup.
 
virtual void serviceStop ()=0
 Non-locking call to initiate service shutdown.
 

Detailed Description

template<typename char_t>
class CppTrail::BasicSyncLoggerImpl< char_t >

A synchronous, thread-safe logger implementation template. This class ensures that every log call is processed immediately on the calling thread. Access to the 'work' function is protected by a mutex, making it safe for multi-threaded environments, though it may introduce latency in the calling thread.

Template Parameters
char_tThe character type (e.g., char, char8_t) used for the log content.
Warning
Ensure that derived classes are stopped before destruction completes to prevent calls to pure virtual methods.

Constructor & Destructor Documentation

◆ ~BasicSyncLoggerImpl()

template<typename char_t >
CppTrail::BasicSyncLoggerImpl< char_t >::~BasicSyncLoggerImpl ( )
overrideprotecteddefault

Destructor.

Warning
Ensure that derived classes are stopped before destruction completes to prevent calls to pure virtual methods.

Member Function Documentation

◆ join()

template<typename char_t >
void CppTrail::BasicSyncLoggerImpl< char_t >::join ( )
inlineoverridevirtual

Waits for the asynchronous end of the shutdown sequence.

This function is used in conjunction with signalStop() to ensure description safety.

Implements CppTrail::BasicLoggerImpl< char_t >.

◆ log()

template<typename char_t >
void CppTrail::BasicSyncLoggerImpl< char_t >::log ( message_type  oMessage)
inlinefinalvirtual

Synchronously processes and records a log message.

This method is the primary entry point for synchronous logging. It performs a thread-safe check of the service status before invoking the internal work() method.

Parameters
oMessageThe message implementation to be recorded. This object is moved into the processing pipeline to avoid unnecessary copies.
Note
Blocking Behavior: This call blocks the execution of the calling thread until the I/O operation (work()) is completed.
Status Check: Messages are only processed if the logger status is Status::RUNNING or Status::TRASCENDENT. In any other state, the message is safely discarded.

Implements CppTrail::BasicLoggerImpl< char_t >.

◆ signalStop()

template<typename char_t >
void CppTrail::BasicSyncLoggerImpl< char_t >::signalStop ( )
inlinefinalvirtual

Signals the logger to stop.

For synchronous loggers, this is functionally equivalent to stop() as there is no background queue to drain.

Implements CppTrail::BasicLoggerImpl< char_t >.

◆ start()

template<typename char_t >
void CppTrail::BasicSyncLoggerImpl< char_t >::start ( )
inlinefinalvirtual

Starts the logger service.

Blocks until the internal serviceStart() completes and the status is RUNNING.

Implements CppTrail::BasicLoggerImpl< char_t >.

◆ status()

template<typename char_t >
Status CppTrail::BasicSyncLoggerImpl< char_t >::status ( )
inlinefinalvirtual

Retrieves the current status of the service.

Returns
The current Status as reported by the underlying service.

Implements CppTrail::BasicLoggerImpl< char_t >.

◆ stop()

template<typename char_t >
void CppTrail::BasicSyncLoggerImpl< char_t >::stop ( )
inlinefinalvirtual

Stops the logger service.

Blocks until the internal serviceStop() completes and the status is STOPPED.

Implements CppTrail::BasicLoggerImpl< char_t >.

◆ work()

template<typename char_t >
virtual void CppTrail::BasicSyncLoggerImpl< char_t >::work ( message_type  oMessage)
protectedpure virtual

Abstract method where the actual logging I/O occurs.

This is called while the general mutex is held.

Parameters
oMessageThe message to be recorded.

The documentation for this class was generated from the following file: