17#include <kcenon/common/interfaces/logger_interface.h>
102 std::ostringstream oss;
106 oss <<
"{" << newline;
112 if (!first) oss <<
"," << newline;
119 if (!first) oss <<
"," << newline;
126 if (!first) oss <<
"," << newline;
132 if (!first) oss <<
"," << newline;
138 std::string file_path = entry.
location->file.to_string();
139 if (!file_path.empty()) {
144 oss <<
"," << newline << indent <<
"\"line\":" << entry.
location->line;
147 std::string func = entry.
location->function.to_string();
155 std::string cat = entry.
category->to_string();
163 if (!entry.
otel_ctx->trace_id.empty()) {
166 if (!entry.
otel_ctx->span_id.empty()) {
169 if (!entry.
otel_ctx->trace_flags.empty()) {
176 for (
const auto& [key, value] : *entry.
fields) {
182 oss << newline <<
"}";
194 return "json_formatter";
204 std::visit([&oss](
const auto& v) {
205 using T = std::decay_t<
decltype(v)>;
206 if constexpr (std::is_same_v<T, std::string>) {
208 }
else if constexpr (std::is_same_v<T, bool>) {
209 oss << (v ?
"true" :
"false");
210 }
else if constexpr (std::is_same_v<T, int64_t>) {
212 }
else if constexpr (std::is_same_v<T, double>) {
213 oss << std::fixed << std::setprecision(6) << v;
std::string to_string() const
Convert to std::string.
static std::string level_to_string(log_level level)
Convert log level to human-readable string.
static std::string escape_json(const std::string &str)
Escape special characters for JSON.
static std::string format_iso8601(const std::chrono::system_clock::time_point &tp)
Format timestamp to ISO 8601 / RFC 3339 format with UTC timezone.
Data structures for representing log entries and source locations kcenon.
std::variant< std::string, int64_t, double, bool > log_value
Value type for structured logging fields.
String utility functions for log formatting and conversion.
Represents a single log entry with all associated metadata.
std::optional< source_location > location
Optional source code location information.
std::optional< log_fields > fields
Optional structured fields for key-value logging.
std::optional< small_string_64 > thread_id
Optional thread identifier.
std::optional< otlp::otel_context > otel_ctx
Optional OpenTelemetry context for trace correlation.
log_level level
Severity level of the log message.
std::optional< small_string_128 > category
Optional category for log filtering and routing.
small_string_256 message
The actual log message.
std::chrono::system_clock::time_point timestamp
Timestamp when the log entry was created.
Time utility functions for timestamp formatting.