|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
JSON formatter for structured logging. More...
#include <base_formatter.h>


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 |
| json_formatter (const format_options &opts=format_options{}) | |
| Constructor with optional format options. | |
| std::string | format (const log_entry &entry) const override |
| Format a log entry to JSON string. | |
| std::string | get_name () const override |
| Get formatter name. | |
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. | |
Private Member Functions | |
| template<typename StringType > | |
| std::string | escape_json (const StringType &str) const |
Static Private Member Functions | |
| static void | format_value (std::ostringstream &oss, const log_value &value) |
| Format a log_value to JSON. | |
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 ×tamp) 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_ |
JSON formatter for structured logging.
Formatter that outputs JSON-structured log messages.
Produces machine-readable JSON output suitable for log aggregation, analysis tools, and automated processing. Supports both compact and pretty-printed output formats.
Features:
Thread-safety: This formatter is stateless and thread-safe.
Definition at line 69 of file json_formatter.h.
|
inlineexplicit |
Constructor with optional format options.
| opts | Initial format options |
Definition at line 79 of file json_formatter.h.
|
inlineprivate |
Definition at line 156 of file base_formatter.h.
Referenced by format().

|
inlineoverridevirtual |
Format a log entry into a string.
| entry | The log entry to format |
Implements kcenon::logger::base_formatter.
Definition at line 124 of file base_formatter.h.
References kcenon::logger::log_entry::category, escape_json(), 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.
Referenced by json_formatter_example().


|
inlineoverridevirtual |
Format a log entry to JSON string.
| entry | The log entry to format |
Produces a JSON object with fields:
Implements kcenon::logger::base_formatter.
Definition at line 101 of file json_formatter.h.
References kcenon::logger::log_entry::category, kcenon::logger::utils::string_utils::escape_json(), kcenon::logger::log_entry::fields, kcenon::logger::utils::time_utils::format_iso8601(), format_value(), kcenon::logger::format_options::include_level, kcenon::logger::format_options::include_source_location, kcenon::logger::format_options::include_thread_id, kcenon::logger::format_options::include_timestamp, kcenon::logger::log_entry::level, kcenon::logger::utils::string_utils::level_to_string(), kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::logger::log_formatter_interface::options_, kcenon::logger::log_entry::otel_ctx, kcenon::logger::format_options::pretty_print, kcenon::logger::log_entry::thread_id, kcenon::logger::log_entry::timestamp, and kcenon::logger::small_string< SSO_SIZE >::to_string().

|
inlinestaticprivate |
Format a log_value to JSON.
| oss | Output stream |
| value | Value to format |
Definition at line 203 of file json_formatter.h.
References kcenon::logger::utils::string_utils::escape_json().
Referenced by format().


|
inlineoverride |
Definition at line 150 of file base_formatter.h.
|
inlineoverridevirtual |
Get formatter name.
Implements kcenon::logger::log_formatter_interface.
Definition at line 193 of file json_formatter.h.