Simple-Log  alpha-v0.7
sl::log::ConsoleSink< TRecord > Class Template Referencefinal

Sink class for directly logging onto std::cout. More...

#include <ConsoleSink.hpp>

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

Public Types

using TextStylePolicy_t = std::function< ConsoleTextStyle(const Record_t &)>
 
using Record_t = std::remove_cvref_t< TRecord >
 Used Record type. More...
 
using FlushPolicy_t = std::unique_ptr< detail::AbstractFlushPolicyWrapper< Record_t > >
 
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

 ConsoleSink ()
 Constructor. More...
 
 ~ConsoleSink () noexcept=default
 Default destructor. More...
 
 ConsoleSink (const ConsoleSink &)=delete
 Deleted copy constructor. More...
 
ConsoleSinkoperator= (const ConsoleSink &)=delete
 Deleted copy assign operator. More...
 
 ConsoleSink (ConsoleSink &&)=delete
 Deleted move constructor. More...
 
ConsoleSinkoperator= (ConsoleSink &&)=delete
 Deleted move assign operator. More...
 
template<ConsoleTextStylePolicyFor< Record_t > TStylePolicy>
void setTextStylePolicy (TStylePolicy &&policy)
 Sets the active ConsoleTextStylePolicy. More...
 
void removeTextStylePolicy ()
 Replaces the current ConsoleTextStylePolicy with the default one. 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...
 

Static Protected Member Functions

static constexpr TextStylePolicy_t defaultTextStylePolicy ()
 Constructs the default TextStylePolicy. More...
 
static constexpr FlushPolicy_t defaultFlushPolicy () noexcept
 
static constexpr Formatter_t defaultFormatter () noexcept
 
static constexpr Filter_t defaultFilter () noexcept
 

Detailed Description

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

Sink class for directly logging onto std::cout.

Template Parameters
TRecordUsed Record type.

This Sink class directly uses a std::cout object for printing each recorded message. Users may register ConsoleTextStyles which will then colorized or printed the messages in a specific style.

Version
since alpha-0.6
Examples
ColorizedConsoleLogging/main.cpp, CustomRecordType/main.cpp, and CustomizeBaseRecord/main.cpp.

Member Typedef Documentation

◆ Filter_t

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

◆ FlushPolicy_t

template<Record TRecord>
using sl::log::OStreamSink< TRecord >::FlushPolicy_t = std::unique_ptr<detail::AbstractFlushPolicyWrapper<Record_t> >
inherited

◆ Formatter_t

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

◆ Projections_t

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

◆ Record_t

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

Used Record type.

◆ TextStylePolicy_t

template<Record TRecord>
using sl::log::ConsoleSink< TRecord >::TextStylePolicy_t = std::function<ConsoleTextStyle(const Record_t&)>

Constructor & Destructor Documentation

◆ ConsoleSink() [1/3]

template<Record TRecord>
sl::log::ConsoleSink< TRecord >::ConsoleSink ( )
inlineexplicit

Constructor.

◆ ~ConsoleSink()

template<Record TRecord>
sl::log::ConsoleSink< TRecord >::~ConsoleSink ( )
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.

◆ ConsoleSink() [2/3]

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

Deleted copy constructor.

◆ ConsoleSink() [3/3]

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

Deleted move constructor.

Member Function Documentation

◆ defaultFilter()

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

◆ defaultFlushPolicy()

template<Record TRecord>
static constexpr FlushPolicy_t sl::log::OStreamSink< TRecord >::defaultFlushPolicy ( )
inlinestaticconstexprprotectednoexceptinherited

◆ defaultFormatter()

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

◆ defaultTextStylePolicy()

template<Record TRecord>
static constexpr TextStylePolicy_t sl::log::ConsoleSink< TRecord >::defaultTextStylePolicy ( )
inlinestaticconstexprprotected

Constructs the default TextStylePolicy.

Returns
a invokable object

◆ flush()

template<Record TRecord>
void sl::log::OStreamSink< TRecord >::flush ( )
inlineinherited

Flushes all pending output of the internal stream.

Remarks
Internally locks the associated stream mutex.

◆ isEnabled()

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

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)
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.

Parameters
recordRecord object

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

◆ operator=() [1/2]

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

Deleted move assign operator.

◆ operator=() [2/2]

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

Deleted copy assign operator.

◆ removeFilter()

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

Replaces the active filter with the default one.

◆ removeFlushPolicy()

template<Record TRecord>
void sl::log::OStreamSink< TRecord >::removeFlushPolicy ( )
inlineinherited

Replaces the current Flush-Policy with the default one.

The default Flush-Policy flushes after each handled Record.

◆ removeFormatter()

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

Replaces the active formatter with the default one.

◆ removeTextStylePolicy()

template<Record TRecord>
void sl::log::ConsoleSink< TRecord >::removeTextStylePolicy ( )
inline

Replaces the current ConsoleTextStylePolicy with the default one.

◆ setEnabled()

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

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)
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:

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.

◆ setFlushPolicy()

template<Record TRecord>
template<FlushPolicyFor< Record_t > TPolicy>
void sl::log::OStreamSink< TRecord >::setFlushPolicy ( TPolicy &&  policy)
inlineinherited

Sets the active Flush-Policy.

Template Parameters
TPolicyType of the passed Flush-Policy (automatically deduced)
Parameters
policyThe new Flush-Policy object

◆ setFormatter()

template<Record TRecord>
template<RecordFormatterFor< Record_t > TFormatter>
void sl::log::BasicSink< TRecord >::setFormatter ( TFormatter &&  formatter)
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:

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

◆ setTextStylePolicy()

template<Record TRecord>
template<ConsoleTextStylePolicyFor< Record_t > TStylePolicy>
void sl::log::ConsoleSink< TRecord >::setTextStylePolicy ( TStylePolicy &&  policy)
inline

Sets the active ConsoleTextStylePolicy.

Template Parameters
TStylePolicyType of the passed ConsoleTextStylePolicy (automatically deduced)
Parameters
policyThe new ConsoleTextStylePolicy object

◆ writeToStream()

template<Record TRecord>
template<class TData >
void sl::log::OStreamSink< TRecord >::writeToStream ( TData &&  data)
inlineprotectedinherited

Writes directly to the internal stream.

Template Parameters
TDataType of data (automatically deduced)
Parameters
dataData 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.

Remarks
If not already locked, this function will lock the stream associated mutex.

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