Simple-Log
alpha-v0.7
|
An std::ostream orientated Sink class which extends BasicSink. More...
#include <OStreamSink.hpp>
Public Types | |
using | FlushPolicy_t = std::unique_ptr< detail::AbstractFlushPolicyWrapper< Record_t > > |
using | Record_t = std::remove_cvref_t< TRecord > |
Used Record type. More... | |
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 &)> |
Public Member Functions | |
OStreamSink (std::ostream &stream) | |
Constructor. More... | |
~OStreamSink () noexcept=default | |
Default destructor. More... | |
OStreamSink (const OStreamSink &)=delete | |
Deleted copy constructor. More... | |
OStreamSink & | operator= (const OStreamSink &)=delete |
Deleted copy assign operator. More... | |
OStreamSink (OStreamSink &&)=delete | |
Deleted move constructor. More... | |
OStreamSink & | operator= (OStreamSink &&)=delete |
Deleted move assign operator. More... | |
template<FlushPolicyFor< Record_t > TPolicy> | |
void | setFlushPolicy (TPolicy &&policy) |
Sets the active Flush-Policy. More... | |
void | removeFlushPolicy () |
Replaces the current Flush-Policy with the default one. More... | |
void | flush () |
Flushes all pending output of the internal stream. 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 | |
template<class TData > | |
void | writeToStream (TData &&data) |
Writes directly to the internal stream. More... | |
virtual void | beforeMessageWrite (const Record_t &record, std::string_view message) |
Virtual method which will be called before the actual message is written to the stream. More... | |
virtual void | afterMessageWrite (const Record_t &record, std::string_view message) |
Virtual method which will be called after the actual message is written to the stream. More... | |
Static Protected Member Functions | |
static constexpr FlushPolicy_t | defaultFlushPolicy () noexcept |
static constexpr Formatter_t | defaultFormatter () noexcept |
static constexpr Filter_t | defaultFilter () noexcept |
An std::ostream orientated Sink class which extends BasicSink.
TRecord | Used Record type. |
This Sink class uses a std::ostream reference for printing each recorded message and offers options to manipulate its behaviour: e.g. filtering and formatting messages. Users which would like to print messages onto the console, there is already an existing class ConsoleSink. For file related logging FileSink might be more suitable.
|
inherited |
using sl::log::OStreamSink< TRecord >::FlushPolicy_t = std::unique_ptr<detail::AbstractFlushPolicyWrapper<Record_t> > |
|
inherited |
|
inherited |
using sl::log::ISink< TRecord >::Record_t = std::remove_cvref_t<TRecord> |
Used Record type.
|
inlineexplicit |
Constructor.
stream | The stream object, which will receive finally formatted messages |
|
defaultnoexcept |
Default destructor.
Destructor does not perform any actions on the internal stream objects, due to it's potential dangling state. Derived classes must handle closing and flushing themselves.
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlineprotectedvirtual |
Virtual method which will be called after the actual message is written to the stream.
record | The current handled Record object |
message | The final message |
|
inlineprotectedvirtual |
Virtual method which will be called before the actual message is written to the stream.
record | The current handled Record object |
message | The final message |
|
inlinestaticconstexprprotectednoexceptinherited |
|
inlinestaticconstexprprotectednoexcept |
|
inlinestaticconstexprprotectednoexceptinherited |
|
inline |
Flushes all pending output of the internal stream.
|
inlinefinaloverridevirtualnoexceptinherited |
Checks if the Sink object is enabled.
Implements sl::log::ISink< TRecord >.
|
inlinefinaloverridevirtualinherited |
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 copy assign operator.
|
delete |
Deleted move assign operator.
|
inlineinherited |
Replaces the active filter with the default one.
|
inline |
Replaces the current Flush-Policy with the default one.
The default Flush-Policy flushes after each handled Record.
|
inlineinherited |
Replaces the active formatter with the default one.
|
inlinefinaloverridevirtualnoexceptinherited |
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 >.
|
inlineinherited |
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 Flush-Policy.
TPolicy | Type of the passed Flush-Policy (automatically deduced) |
policy | The new Flush-Policy object |
|
inlineinherited |
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 |
|
inlineprotected |
Writes directly to the internal stream.
TData | Type of data (automatically deduced) |
data | Data which will be written to the stream. |
This functions writes directly to the stream object. No filter or formatter will be involved and stream will be flush afterwards. This might be useful for writing custom header or footer data to the stream.