Simple-Log
alpha-v0.7
|
Abstract Sink class which offers basic filtering, formatting functionality. More...
#include <BasicSink.hpp>
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... | |
BasicSink & | operator= (const BasicSink &)=delete |
Deleted copy assign operator. More... | |
BasicSink (BasicSink &&)=delete | |
Deleted move constructor. More... | |
BasicSink & | operator= (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 |
Abstract Sink class which offers basic filtering, formatting functionality.
TRecord | Used 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.
using sl::log::BasicSink< TRecord >::Filter_t = std::function<bool(const Record_t&)> |
using sl::log::BasicSink< TRecord >::Formatter_t = std::function<std::string(const Record_t&)> |
using sl::log::BasicSink< TRecord >::Projections_t = RecordGetters<Record_t> |
using sl::log::ISink< TRecord >::Record_t = std::remove_cvref_t<TRecord> |
Used Record type.
|
explicitdefaultnoexcept |
Constructor.
|
defaultnoexcept |
Default destructor.
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlinestaticconstexprprotectednoexcept |
|
inlinestaticconstexprprotectednoexcept |
|
inlinefinaloverridevirtualnoexcept |
Checks if the Sink object is enabled.
Implements sl::log::ISink< TRecord >.
|
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.
record | Record object |
Implements sl::log::ISink< TRecord >.
|
delete |
Deleted move assign operator.
|
delete |
Deleted copy assign operator.
|
inline |
Replaces the active filter with the default one.
|
inline |
Replaces the active formatter with the default one.
|
inlinefinaloverridevirtualnoexcept |
Enables or disables the Sink object.
Disabled Sinks will not handle any incoming Record s
enable | True will enable the Sink object. |
Implements sl::log::ISink< TRecord >.
|
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:
TFilter | Type of the passed filter (automatically deduced) |
filter | An invokable filter object |
|
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:
TFormatter | Type of the passed formatter (automatically deduced) |
formatter | An invokable formatter object |
|
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.
record | The Record object. |
message | The actual message, which should be printed. |