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

Simple plain text formatter. More...

#include <base_formatter.h>

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

Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from kcenon::logger::base_formatter
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.
 
- Protected Attributes inherited from kcenon::logger::log_formatter_interface
format_options options_
 

Detailed Description

Simple plain text formatter.

Definition at line 87 of file base_formatter.h.

Member Function Documentation

◆ format()

std::string kcenon::logger::plain_formatter::format ( const log_entry & entry) const
inlineoverridevirtual

Format a log entry into a string.

Parameters
entryThe log entry to format
Returns
Formatted string representation

Implements kcenon::logger::base_formatter.

Definition at line 89 of file base_formatter.h.

89 {
90 std::ostringstream oss;
91
92 // Format: [TIMESTAMP] [LEVEL] [THREAD] MESSAGE [FILE:LINE:FUNCTION]
93 oss << "[" << format_timestamp(entry.timestamp) << "] ";
94 oss << "[" << level_to_string(entry.level) << "] ";
95
96 if (entry.thread_id) {
97 oss << "[" << std::string_view(*entry.thread_id) << "] ";
98 } else {
99 oss << "[" << get_thread_id() << "] ";
100 }
101
102 oss << std::string_view(entry.message);
103
104 if (entry.location) {
105 oss << " [" << std::string_view(entry.location->file)
106 << ":" << entry.location->line
107 << ":" << std::string_view(entry.location->function) << "]";
108 }
109
110 return oss.str();
111 }
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.

References kcenon::logger::base_formatter::format_timestamp(), kcenon::logger::base_formatter::get_thread_id(), kcenon::logger::log_entry::level, kcenon::logger::base_formatter::level_to_string(), kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::logger::log_entry::thread_id, and kcenon::logger::log_entry::timestamp.

Here is the call graph for this function:

◆ get_format_type()

std::string kcenon::logger::plain_formatter::get_format_type ( ) const
inlineoverride

Definition at line 113 of file base_formatter.h.

113 {
114 return "plain";
115 }

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