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

Base implementation for log formatters. More...

#include <base_formatter.h>

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

Public Member Functions

virtual ~base_formatter ()=default
 
virtual std::string format (const log_entry &entry) const override=0
 Format a log entry into a string.
 
- Public Member Functions inherited from kcenon::logger::log_formatter_interface
virtual ~log_formatter_interface ()=default
 
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 Member Functions

std::string level_to_string (log_level level) const
 Convert log level to string.
 
std::string format_timestamp (const std::chrono::system_clock::time_point &timestamp) const
 Format timestamp to ISO8601 string.
 
std::string get_thread_id () const
 Get current thread ID as string.
 

Additional Inherited Members

- Protected Attributes inherited from kcenon::logger::log_formatter_interface
format_options options_
 

Detailed Description

Base implementation for log formatters.

Provides common formatting functionality for derived formatters.

Definition at line 31 of file base_formatter.h.

Constructor & Destructor Documentation

◆ ~base_formatter()

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

Member Function Documentation

◆ format()

virtual std::string kcenon::logger::base_formatter::format ( const log_entry & entry) const
overridepure virtual

Format a log entry into a string.

Parameters
entryThe log entry to format
Returns
Formatted string representation

Implements kcenon::logger::log_formatter_interface.

Implemented in kcenon::logger::compact_formatter, kcenon::logger::json_formatter, kcenon::logger::json_formatter, and kcenon::logger::plain_formatter.

◆ format_timestamp()

std::string kcenon::logger::base_formatter::format_timestamp ( const std::chrono::system_clock::time_point & timestamp) const
inlineprotected

Format timestamp to ISO8601 string.

Parameters
timestampTime point to format
Returns
ISO8601 formatted string

Definition at line 65 of file base_formatter.h.

65 {
66 auto time_t = std::chrono::system_clock::to_time_t(timestamp);
67 std::ostringstream oss;
68 oss << std::put_time(std::gmtime(&time_t), "%Y-%m-%dT%H:%M:%SZ");
69 return oss.str();
70 }

Referenced by kcenon::logger::json_formatter::format(), and kcenon::logger::plain_formatter::format().

Here is the caller graph for this function:

◆ get_thread_id()

std::string kcenon::logger::base_formatter::get_thread_id ( ) const
inlineprotected

Get current thread ID as string.

Returns
Thread ID string

Definition at line 76 of file base_formatter.h.

76 {
77 std::ostringstream oss;
78 oss << std::this_thread::get_id();
79 return oss.str();
80 }

Referenced by kcenon::logger::json_formatter::format(), and kcenon::logger::plain_formatter::format().

Here is the caller graph for this function:

◆ level_to_string()

std::string kcenon::logger::base_formatter::level_to_string ( log_level level) const
inlineprotected

Convert log level to string.

Parameters
levelLog level
Returns
String representation

Definition at line 48 of file base_formatter.h.

48 {
49 switch (level) {
50 case log_level::critical: return "CRITICAL";
51 case log_level::error: return "ERROR";
52 case log_level::warning: return "WARNING";
53 case log_level::info: return "INFO";
54 case log_level::debug: return "DEBUG";
55 case log_level::trace: return "TRACE";
56 default: return "UNKNOWN";
57 }
58 }

Referenced by kcenon::logger::compact_formatter::format(), kcenon::logger::json_formatter::format(), and kcenon::logger::plain_formatter::format().

Here is the caller graph for this function:

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