Simple-Log  alpha-v0.7
sl::log::BasicSink< TRecord > Class Template Referenceabstract

Abstract Sink class which offers basic filtering, formatting functionality. More...

#include <BasicSink.hpp>

Inheritance diagram for sl::log::BasicSink< TRecord >:
sl::log::ISink< TRecord > sl::log::OStreamSink< TRecord > sl::log::ConsoleSink< TRecord > sl::log::FileSink< TRecord >

Public Types

using Projections_t = RecordGetters< Record_t >
 
using Formatter_t = std::function< std::string(const Record_t &)>
 
using Filter_t = std::function< bool(const Record_t &)>
 
using Record_t = std::remove_cvref_t< TRecord >
 Used Record type. More...
 

Public Member Functions

 BasicSink () noexcept=default
 Constructor. More...
 
 ~BasicSink () noexcept=default
 Default destructor. More...
 
 BasicSink (const BasicSink &)=delete
 Deleted copy constructor. More...
 
BasicSinkoperator= (const BasicSink &)=delete
 Deleted copy assign operator. More...
 
 BasicSink (BasicSink &&)=delete
 Deleted move constructor. More...
 
BasicSinkoperator= (BasicSink &&)=delete
 Deleted move assign operator. More...
 
void log (const Record_t &record) final override
 Handles the given Record object. More...
 
void setEnabled (bool enable=true) noexcept final override
 Enables or disables the Sink object. More...
 
bool isEnabled () const noexcept final override
 Checks if the Sink object is enabled. More...
 
template<RecordFormatterFor< Record_t > TFormatter>
void setFormatter (TFormatter &&formatter)
 Sets the active formatter. More...
 
void removeFormatter ()
 Replaces the active formatter with the default one. More...
 
template<RecordFilterFor< Record_t > TFilter>
void setFilter (TFilter &&filter)
 Sets the active filter. More...
 
void removeFilter ()
 Replaces the active filter with the default one. More...
 

Protected Member Functions

virtual void writeMessage (const Record_t &record, std::string_view message)=0
 This function will be called when the actual message should be printed. More...
 

Static Protected Member Functions

static constexpr Formatter_t defaultFormatter () noexcept
 
static constexpr Filter_t defaultFilter () noexcept
 

Detailed Description

template<Record TRecord>
class sl::log::BasicSink< TRecord >

Abstract Sink class which offers basic filtering, formatting functionality.

Template Parameters
TRecordUsed Record type.

This Sink class implements the enabling functionality, as well as filtering and formatting Records. Users who want to print messages into a std::ostream like object, should look at the OStreamSink or its derived classes.

Member Typedef Documentation

◆ Filter_t

template<Record TRecord>
using sl::log::BasicSink< TRecord >::Filter_t = std::function<bool(const Record_t&)>

◆ Formatter_t

template<Record TRecord>
using sl::log::BasicSink< TRecord >::Formatter_t = std::function<std::string(const Record_t&)>

◆ Projections_t

template<Record TRecord>
using sl::log::BasicSink< TRecord >::Projections_t = RecordGetters<Record_t>

◆ Record_t

template<Record TRecord>
using sl::log::ISink< TRecord >::Record_t = std::remove_cvref_t<TRecord>

Used Record type.

Constructor & Destructor Documentation

◆ BasicSink() [1/3]

template<Record TRecord>
sl::log::BasicSink< TRecord >::BasicSink ( )
explicitdefaultnoexcept

Constructor.

◆ ~BasicSink()

template<Record TRecord>
sl::log::BasicSink< TRecord >::~BasicSink ( )
defaultnoexcept

Default destructor.

◆ BasicSink() [2/3]

template<Record TRecord>
sl::log::BasicSink< TRecord >::BasicSink ( const BasicSink< TRecord > &  )
delete

Deleted copy constructor.

◆ BasicSink() [3/3]

template<Record TRecord>
sl::log::BasicSink< TRecord >::BasicSink ( BasicSink< TRecord > &&  )
delete

Deleted move constructor.

Member Function Documentation

◆ defaultFilter()

template<Record TRecord>
static constexpr Filter_t sl::log::BasicSink< TRecord >::defaultFilter ( )
inlinestaticconstexprprotectednoexcept

◆ defaultFormatter()

template<Record TRecord>
static constexpr Formatter_t sl::log::BasicSink< TRecord >::defaultFormatter ( )
inlinestaticconstexprprotectednoexcept

◆ isEnabled()

template<Record TRecord>
bool sl::log::BasicSink< TRecord >::isEnabled ( ) const
inlinefinaloverridevirtualnoexcept

Checks if the Sink object is enabled.

Returns
Returns true if object is enabled.

Implements sl::log::ISink< TRecord >.

◆ log()

template<Record TRecord>
void sl::log::BasicSink< TRecord >::log ( const Record_t record)
inlinefinaloverridevirtual

Handles the given Record object.

Before the Record gets passed to the actual destination, it will be checked if the Sink object is enabled and if the Record should be filtered. If these checks are passed, the abstract writeMessage function will be invoked with the finally formatted message string.

Parameters
recordRecord object

Implements sl::log::ISink< TRecord >.

◆ operator=() [1/2]

template<Record TRecord>
BasicSink& sl::log::BasicSink< TRecord >::operator= ( BasicSink< TRecord > &&  )
delete

Deleted move assign operator.

◆ operator=() [2/2]

template<Record TRecord>
BasicSink& sl::log::BasicSink< TRecord >::operator= ( const BasicSink< TRecord > &  )
delete

Deleted copy assign operator.

◆ removeFilter()

template<Record TRecord>
void sl::log::BasicSink< TRecord >::removeFilter ( )
inline

Replaces the active filter with the default one.

◆ removeFormatter()

template<Record TRecord>
void sl::log::BasicSink< TRecord >::removeFormatter ( )
inline

Replaces the active formatter with the default one.

◆ setEnabled()

template<Record TRecord>
void sl::log::BasicSink< TRecord >::setEnabled ( bool  enable = true)
inlinefinaloverridevirtualnoexcept

Enables or disables the Sink object.

Disabled Sinks will not handle any incoming Record s

Parameters
enableTrue will enable the Sink object.

Implements sl::log::ISink< TRecord >.

◆ setFilter()

template<Record TRecord>
template<RecordFilterFor< Record_t > TFilter>
void sl::log::BasicSink< TRecord >::setFilter ( TFilter &&  filter)
inline

Sets the active filter.

It's the filters job to decide, which Record will be printed (filter returns true) and which will be skipped (filter returns false). Therefore a filter must be an invokable of the following signature:

bool(const Record&)
concept Record
Concept which all the necessary concepts for Record types.
Definition: Record.hpp:204
Remarks
The filters return type doesn't have to be bool, but the returned object must at least be implicitly convertible to bool.
Template Parameters
TFilterType of the passed filter (automatically deduced)
Parameters
filterAn invokable filter object
Examples
FileLogging/main.cpp.

◆ setFormatter()

template<Record TRecord>
template<RecordFormatterFor< Record_t > TFormatter>
void sl::log::BasicSink< TRecord >::setFormatter ( TFormatter &&  formatter)
inline

Sets the active formatter.

It's the formatters job to extract the necessary information from Records and built the final message string.

A custom formatter should use the following signature:

std::string(const Record&)
Template Parameters
TFormatterType of the passed formatter (automatically deduced)
Parameters
formatterAn invokable formatter object

◆ writeMessage()

template<Record TRecord>
virtual void sl::log::BasicSink< TRecord >::writeMessage ( const Record_t record,
std::string_view  message 
)
protectedpure virtual

This function will be called when the actual message should be printed.

Subclasses must implement this function and have to print the message to the desired destination themselves.

Parameters
recordThe Record object.
messageThe actual message, which should be printed.
Version
since alpha-0.6

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