ealogger
ealogger is a c++ library that provides a blazing fast and easy to use logging mechanism
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ealogger::Sink Class Referenceabstract

A sink is an object that writes the log message to a specific target. More...

#include <sink.h>

Inheritance diagram for ealogger::Sink:
ealogger::SinkConsole ealogger::SinkFile ealogger::SinkSyslog

Public Member Functions

 Sink (std::string msg_template, std::string datetime_pattern, bool enabled, ealogger::constants::LOG_LEVEL min_lvl)
 Sink constructor. More...
 
void set_msg_template (std::string msg_template)
 Set the message template with conversion patterns. More...
 
void set_datetime_pattern (std::string datetime_pattern)
 Set the date time conversion pattern. More...
 
void set_enabled (bool enabled)
 Enable or disable the sink. More...
 
bool get_enabled ()
 Check if this sink is enabled. More...
 
void set_min_lvl (ealogger::constants::LOG_LEVEL min_lvl)
 Set minimum severity for this sink. More...
 
void prepare_log_message (const std::shared_ptr< LogMessage > &log_message)
 Prepare a log message before it is written to the targets. More...
 

Protected Member Functions

void fill_conv_patterns (bool lock)
 Fill Sink::vec_conv_patterns with ConverionPattern depending on Sink::msg_template.
 
virtual void write_message (const std::string &msg)=0
 Writes a LogMessage object to the logger sink. More...
 
virtual void config_changed ()=0
 This method will be called when the SinkConfig option changes. More...
 

Protected Attributes

std::string msg_template
 
std::string datetime_pattern
 
bool enabled
 
ealogger::constants::LOG_LEVEL min_level
 
std::mutex mtx_msg_template
 
std::mutex mtx_datetime_pattern
 
std::mutex mtx_enabled
 
std::mutex mtx_min_lvl
 
std::mutex mtx_conv_pattern
 
std::vector< ConversionPatternvec_conv_patterns
 
std::map< ealogger::constants::LOG_LEVEL, std::string > loglevel_lookup
 

Detailed Description

A sink is an object that writes the log message to a specific target.

Author
Christian Rapp

The virtual class Sink has to be implemented by each possible target. To add a new Sink to ealogger you have to provide an implementation for Sink::write_message

Constructor & Destructor Documentation

ealogger::Sink::Sink ( std::string  msg_template,
std::string  datetime_pattern,
bool  enabled,
ealogger::constants::LOG_LEVEL  min_lvl 
)

Sink constructor.

Parameters
msg_templateMessage template for this sink
datetime_patterndatetime conversion pattern
enabledWhether or not this sink is enabled
min_lvlThe minimum log severity

A Log message can use conversion patterns in the message template msg_template. Every Sink uses its own message template.

Internally std::strftime is used from header ctime to create formatted time strings. So for parameter Sink::datetime_pattern you have to use conversion patterns that are recognised by strftime For example "%H:%M:%S" returns a 24-hour based time string like 20:12:02

Note
Sink objects are not exposed to the user directly. You have to use the Logger class to change a sinks settings. Some options for a Sink are only exposed via Logger::init_sink_* methods.
See also
ConversionPattern

Member Function Documentation

virtual void ealogger::Sink::config_changed ( )
protectedpure virtual

This method will be called when the SinkConfig option changes.

Derived Sink classes have to implement this and take necessary steps regarding a changed configuration file

bool ealogger::Sink::get_enabled ( )

Check if this sink is enabled.

Returns
void ealogger::Sink::prepare_log_message ( const std::shared_ptr< LogMessage > &  log_message)

Prepare a log message before it is written to the targets.

Parameters
log_message

Preparing means conversion patterns will be substituted with the corresponding information

void ealogger::Sink::set_datetime_pattern ( std::string  datetime_pattern)

Set the date time conversion pattern.

Parameters
datetime_pattern

You can use all conversion patterns that are used by strftime The position of the date time information can be specified with ealogger ConversionPattern.

void ealogger::Sink::set_enabled ( bool  enabled)

Enable or disable the sink.

Parameters
enabled
void ealogger::Sink::set_min_lvl ( ealogger::constants::LOG_LEVEL  min_lvl)

Set minimum severity for this sink.

Parameters
min_lvl
void ealogger::Sink::set_msg_template ( std::string  msg_template)

Set the message template with conversion patterns.

Parameters
msg_template

You can define a message template for every Sink. Every conversion specifier will be substituted with the corresponding information.

See also
ConversionPattern
virtual void ealogger::Sink::write_message ( const std::string &  msg)
protectedpure virtual

Writes a LogMessage object to the logger sink.

Parameters
msgLogMessage object

This interface method has to be implemented by every logger sink. The sink is required to format the log message according to Sink::msg_template and Sink::datetime_pattern. After the message is ready it will be written to the specified sink.

Member Data Documentation

std::string ealogger::Sink::datetime_pattern
protected

Date / time conversion pattern

bool ealogger::Sink::enabled
protected

Is this Sink enabled

std::map<ealogger::constants::LOG_LEVEL, std::string> ealogger::Sink::loglevel_lookup
protected

Lookup table for loglevel Strings

ealogger::constants::LOG_LEVEL ealogger::Sink::min_level
protected

Minimum log message severity for this sink

std::string ealogger::Sink::msg_template
protected

Message template string consisting of conversion patterns

std::mutex ealogger::Sink::mtx_conv_pattern
protected
std::mutex ealogger::Sink::mtx_datetime_pattern
protected
std::mutex ealogger::Sink::mtx_enabled
protected
std::mutex ealogger::Sink::mtx_min_lvl
protected

Sink::min_levek mutex

std::mutex ealogger::Sink::mtx_msg_template
protected
std::vector<ConversionPattern> ealogger::Sink::vec_conv_patterns
protected

Vector of conversion patterns a Sink uses


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