ealogger
ealogger is a c++ library that provides a blazing fast and easy to use logging mechanism
|
A sink is an object that writes the log message to a specific target. More...
#include <sink.h>
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< ConversionPattern > | vec_conv_patterns |
std::map< ealogger::constants::LOG_LEVEL, std::string > | loglevel_lookup |
A sink is an object that writes the log message to a specific target.
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
ealogger::Sink::Sink | ( | std::string | msg_template, |
std::string | datetime_pattern, | ||
bool | enabled, | ||
ealogger::constants::LOG_LEVEL | min_lvl | ||
) |
Sink constructor.
msg_template | Message template for this sink |
datetime_pattern | datetime conversion pattern |
enabled | Whether or not this sink is enabled |
min_lvl | The 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
|
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.
void ealogger::Sink::prepare_log_message | ( | const std::shared_ptr< LogMessage > & | log_message | ) |
Prepare a log message before it is written to the targets.
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.
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.
enabled |
void ealogger::Sink::set_min_lvl | ( | ealogger::constants::LOG_LEVEL | min_lvl | ) |
Set minimum severity for this sink.
min_lvl |
void ealogger::Sink::set_msg_template | ( | std::string | msg_template | ) |
Set the message template with conversion patterns.
msg_template |
You can define a message template for every Sink. Every conversion specifier will be substituted with the corresponding information.
|
protectedpure virtual |
Writes a LogMessage object to the logger sink.
msg | LogMessage 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.
|
protected |
Date / time conversion pattern
|
protected |
Is this Sink enabled
|
protected |
Lookup table for loglevel Strings
|
protected |
Minimum log message severity for this sink
|
protected |
Message template string consisting of conversion patterns
|
protected |
Sink::vec_conv_patterns mutex
|
protected |
Sink::datetime_pattern mutex
|
protected |
Sink::enabled mutex
|
protected |
Sink::min_levek mutex
|
protected |
Sink::msg_template mutex
|
protected |
Vector of conversion patterns a Sink uses