Simple-Log  alpha-v0.7
sl::log::Core< TRecord > Class Template Reference

The central point of the whole library. Needs to be instantiated at least once. More...

#include <Core.hpp>

Public Types

using Record_t = std::remove_cvref_t< TRecord >
 

Public Member Functions

 Core () noexcept
 Default Constructor. More...
 
 ~Core () noexcept
 Destructor. More...
 
 Core (const Core &)=delete
 Deleted copy constructor. More...
 
Coreoperator= (const Core &)=delete
 Deleted copy assign operator. More...
 
 Core (Core &&)=delete
 Deleted move constructor. More...
 
Coreoperator= (Core &&)=delete
 Deleted move assign operator. More...
 
void log (Record_t &&record)
 Queues the Record internally. More...
 
template<std::derived_from< ISink_t > TSink, class... TArgs>
requires std::constructible_from< TSink, TArgs... > TSink & makeSink (TArgs &&... args)
 Creates Sink and registers it at this Core instance. More...
 
template<std::derived_from< ISink_t > TSink, class... TArgs>
requires std::constructible_from< TSink, TArgs... > ScopedSinkDisabling< Record_t, TSink > makeDisabledSink (TArgs &&... args)
 Creates Sink disabled and registers it at this Core instance. More...
 
bool removeSink (const ISink_t &sink)
 Removes the given Sink and destroys it. More...
 

Detailed Description

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

The central point of the whole library. Needs to be instantiated at least once.

Template Parameters
TRecordUsed Record type.

Objects of this class act like a broker between the (multiple) Logger s on the frontend and the (multiple) Sink s on the backend. Due to this there must at least one living instance of Core during the whole program runtime, but it isn't restricted to exist uniquely. It can be totally fine to create one global Core, which will be used for general logging purposes, and multiple others for a much lesser scope, like state logging on entity level. Logger will be permanently linked to one specific Core instance, thus Core instances must outlive their corresponding Logger s.

Each instance of Core consists of the following:

  • one BlockingQueue in which all Records will get added
  • multiple Sink objects
  • one Worker thread, which will pull Records from that BlockingQueue and hand them over to the Sinks

Due to this the Core is thread-safe by design.

It is fine to add Sinks during later stages of your program. This hasn't necessarily to be done right after Core's creation. When Core goes out of scope, or is about to get destructed otherwise, it will block any new Records which could be pushed into but will also let the Worker finish its work. Therefor it will wait in the destructor, unless there is an exception throwing, in which case Core will force the Worker to quit its work instantly.

Core instances are neither copy- nor movable.

Examples
ColorizedConsoleLogging/main.cpp, CustomRecordType/main.cpp, and CustomizeBaseRecord/main.cpp.

Member Typedef Documentation

◆ Record_t

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

Constructor & Destructor Documentation

◆ Core() [1/3]

template<Record TRecord>
sl::log::Core< TRecord >::Core ( )
inlinenoexcept

Default Constructor.

The internal Worker thread will directly start running.

◆ ~Core()

template<Record TRecord>
sl::log::Core< TRecord >::~Core ( )
inlinenoexcept

Destructor.

Will block until the internal Record queue is empty or an exception rises, which will then force the Worker thread to quit.

◆ Core() [2/3]

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

Deleted copy constructor.

◆ Core() [3/3]

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

Deleted move constructor.

Member Function Documentation

◆ log()

template<Record TRecord>
void sl::log::Core< TRecord >::log ( Record_t &&  record)
inline

Queues the Record internally.

Parameters
recordThe record which will be queued

This function should not be called directly on logging purposes. It serves as a simple interface for the corresponding Logger objects.

◆ makeDisabledSink()

template<Record TRecord>
template<std::derived_from< ISink_t > TSink, class... TArgs>
requires std::constructible_from<TSink, TArgs...> ScopedSinkDisabling<Record_t, TSink> sl::log::Core< TRecord >::makeDisabledSink ( TArgs &&...  args)
inline

Creates Sink disabled and registers it at this Core instance.

Template Parameters
TSinkConcrete Sink type
TArgsConstructor argument types (will be deducted automatically)
Parameters
argsThe constructor arguments for the newly generated Sink object. Will be forwarded as is.
Returns
Wrapped reference to the managed Sink object.

This function creates a new disabled Sink object and returns a wrapped reference to the caller. When this wrapper goes out of scope or gets destructed otherwise, the attached Sink will become enabled. Use this if you want to make sure, that no messages will be handled before your Sink is finally setup. This Sink will be linked to and managed by the called Core instance.

Examples
CustomRecordType/main.cpp, and CustomizeBaseRecord/main.cpp.

◆ makeSink()

template<Record TRecord>
template<std::derived_from< ISink_t > TSink, class... TArgs>
requires std::constructible_from<TSink, TArgs...> TSink& sl::log::Core< TRecord >::makeSink ( TArgs &&...  args)
inline

Creates Sink and registers it at this Core instance.

Template Parameters
TSinkConcrete Sink type
TArgsConstructor argument types (will be deducted automatically)
Parameters
argsThe constructor arguments for the newly generated Sink object. Will be forwarded as is.
Returns
reference to the managed Sink object

This function creates a new Sink object and returns a reference to the caller. This Sink will be linked to and managed by the called Core instance.

Examples
ColorizedConsoleLogging/main.cpp, and FileLogging/main.cpp.

◆ operator=() [1/2]

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

Deleted copy assign operator.

◆ operator=() [2/2]

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

Deleted move assign operator.

◆ removeSink()

template<Record TRecord>
bool sl::log::Core< TRecord >::removeSink ( const ISink_t sink)
inline

Removes the given Sink and destroys it.

Parameters
sinkThe sink which will be destroyed
Returns
Returns true, if sink has been destroyed.

If this sink is registered at this Core instance, then it will be destroyed immediately. Otherwise nothing will change.


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