Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::log_formatter_interface Class Referenceabstract

Abstract interface for log message formatters. More...

#include <log_formatter_interface.h>

Inheritance diagram for kcenon::logger::log_formatter_interface:
Inheritance graph
Collaboration diagram for kcenon::logger::log_formatter_interface:
Collaboration graph

Public Member Functions

virtual ~log_formatter_interface ()=default
 
virtual std::string format (const log_entry &entry) const =0
 Format a log entry to a string.
 
virtual void set_options (const format_options &opts)
 Set formatting options.
 
virtual format_options get_options () const
 Get current formatting options.
 
virtual std::string get_name () const =0
 

Protected Attributes

format_options options_
 

Detailed Description

Abstract interface for log message formatters.

Defines the contract that all log formatters must implement. Formatters are responsible for converting log_entry structures into formatted strings ready for output.

Thread-safety: Formatters should be thread-safe as they may be called concurrently from multiple threads when used with async writers.

Note
Implementations should be stateless when possible to ensure thread safety.
Since
1.2.0

Definition at line 73 of file log_formatter_interface.h.

Constructor & Destructor Documentation

◆ ~log_formatter_interface()

virtual kcenon::logger::log_formatter_interface::~log_formatter_interface ( )
virtualdefault

Member Function Documentation

◆ format()

virtual std::string kcenon::logger::log_formatter_interface::format ( const log_entry & entry) const
pure virtual

Format a log entry to a string.

Parameters
entryThe log entry to format
Returns
Formatted string ready for output

Converts the log_entry structure into a formatted string according to the formatter's specific format (text, JSON, XML, etc.).

Note
This method must be thread-safe.
Warning
Implementations should handle empty/null fields gracefully.
Since
1.2.0

Implemented in kcenon::logger::base_formatter, kcenon::logger::compact_formatter, kcenon::logger::json_formatter, kcenon::logger::json_formatter, kcenon::logger::logfmt_formatter, kcenon::logger::plain_formatter, kcenon::logger::template_formatter, and kcenon::logger::timestamp_formatter.

◆ get_name()

virtual std::string kcenon::logger::log_formatter_interface::get_name ( ) const
pure virtual

◆ get_options()

virtual format_options kcenon::logger::log_formatter_interface::get_options ( ) const
inlinevirtual

Get current formatting options.

Returns
Current format options
Since
1.2.0

Definition at line 114 of file log_formatter_interface.h.

114 {
115 return options_;
116 }

References options_.

◆ set_options()

virtual void kcenon::logger::log_formatter_interface::set_options ( const format_options & opts)
inlinevirtual

Set formatting options.

Parameters
optsConfiguration options for formatting

Allows runtime configuration of which elements to include in the formatted output. Not all formatters may support all options.

Note
Default implementation stores options in protected member.
Since
1.2.0

Definition at line 104 of file log_formatter_interface.h.

104 {
105 options_ = opts;
106 }

References options_.

Member Data Documentation

◆ options_


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