Chatsync  bbffde5c0c672a526bdc83637acf66dc20a80fbf
logging::LoggerImpl Class Reference

#include <logging.hpp>

Public Member Functions

 LoggerImpl (LoggerImpl const &)=delete
 
 LoggerImpl (LoggerImpl &&)=delete
 
LoggerImploperator= (LoggerImpl const &)=delete
 
LoggerImploperator= (LoggerImpl &&)=delete
 
void log (const LogMessage &&msg)
 
void setOutput (const std::shared_ptr< LogSink > &output)
 

Static Public Member Functions

static LoggerImplget ()
 

Protected Member Functions

 LoggerImpl ()
 
 ~LoggerImpl ()
 

Private Member Functions

void writeOut ()
 

Private Attributes

std::queue< LogMessage_messages
 
std::mutex _mutex
 
std::condition_variable _cond
 
std::unique_ptr< std::thread > _writer
 
std::atomic_bool _running
 
unsigned int _log_repeat
 
std::weak_ptr< LogSink_sink
 

Detailed Description

Implementation of the logger singleton.

The logger will gather the messages inside LoggerImpl::_messages until the LoggerImpl::setOutput() is called and the sink is set. After start the logs will be redirected to sink while it's functional.

If the sink becomes unavailable the log messages are collected inside the LoggerImpl::_messages again and may possibly lead to large memory usage.

Constructor & Destructor Documentation

§ LoggerImpl() [1/3]

logging::LoggerImpl::LoggerImpl ( LoggerImpl const &  )
delete

§ LoggerImpl() [2/3]

logging::LoggerImpl::LoggerImpl ( LoggerImpl &&  )
delete

§ LoggerImpl() [3/3]

logging::LoggerImpl::LoggerImpl ( )
inlineprotected

§ ~LoggerImpl()

logging::LoggerImpl::~LoggerImpl ( )
inlineprotected

Member Function Documentation

§ get()

LoggerImpl & logging::LoggerImpl::get ( )
static

Access point to the singleton

§ log()

void logging::LoggerImpl::log ( const LogMessage &&  msg)

Just pushs the msg to the _messages queue

§ operator=() [1/2]

LoggerImpl& logging::LoggerImpl::operator= ( LoggerImpl const &  )
delete

§ operator=() [2/2]

LoggerImpl& logging::LoggerImpl::operator= ( LoggerImpl &&  )
delete

§ setOutput()

void logging::LoggerImpl::setOutput ( const std::shared_ptr< LogSink > &  output)

Switch on output and start logging.

Parameters
outputThe prepared logging::LogSink to write the logs.

§ writeOut()

void logging::LoggerImpl::writeOut ( )
private

The main thread function for the output.

Pops out the messages from the thread and calls LoggerImpl::_sink->write()

Field Documentation

§ _cond

std::condition_variable logging::LoggerImpl::_cond
private

The var to signal new messages

§ _log_repeat

unsigned int logging::LoggerImpl::_log_repeat
private

Repeats for writing logs

§ _messages

std::queue<LogMessage> logging::LoggerImpl::_messages
private

Message queue

§ _mutex

std::mutex logging::LoggerImpl::_mutex
private

Message queue lock

§ _running

std::atomic_bool logging::LoggerImpl::_running
private

Writing logs is active

§ _sink

std::weak_ptr<LogSink> logging::LoggerImpl::_sink
private

Place to send messages

§ _writer

std::unique_ptr<std::thread> logging::LoggerImpl::_writer
private

Thread for outing


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