42#include <kcenon/common/interfaces/logger_interface.h>
47using log_level = common::interfaces::log_level;
104 std::ostringstream oss;
136 std::string file_path = entry.
location->file.to_string();
137 if (!file_path.empty()) {
142 oss <<
" line=" << entry.
location->line;
145 std::string func = entry.
location->function.to_string();
153 std::string cat = entry.
category->to_string();
161 if (!entry.
otel_ctx->trace_id.empty()) {
162 oss <<
" trace_id=" << entry.
otel_ctx->trace_id;
164 if (!entry.
otel_ctx->span_id.empty()) {
165 oss <<
" span_id=" << entry.
otel_ctx->span_id;
167 if (!entry.
otel_ctx->trace_flags.empty()) {
168 oss <<
" trace_flags=" << entry.
otel_ctx->trace_flags;
174 for (
const auto& [key, value] : *entry.
fields) {
189 [[nodiscard]] std::string
get_name()
const override {
190 return "logfmt_formatter";
201 case log_level::trace:
return "trace";
202 case log_level::debug:
return "debug";
203 case log_level::info:
return "info";
204 case log_level::warning:
return "warn";
205 case log_level::error:
return "error";
206 case log_level::critical:
return "critical";
207 case log_level::off:
return "off";
208 default:
return "unknown";
219 result.reserve(key.size());
221 if (c ==
' ' || c ==
'=' || c ==
'"' || c ==
'\n' || c ==
'\t') {
240 bool needs_quoting =
false;
241 for (
char c : value) {
242 if (c ==
' ' || c ==
'"' || c ==
'=' || c ==
'\n' || c ==
'\t' || c ==
'\r') {
243 needs_quoting =
true;
248 if (!needs_quoting && !value.empty()) {
253 std::ostringstream oss;
255 for (
char c : value) {
257 case '"': oss <<
"\\\"";
break;
258 case '\\': oss <<
"\\\\";
break;
259 case '\n': oss <<
"\\n";
break;
260 case '\r': oss <<
"\\r";
break;
261 case '\t': oss <<
"\\t";
break;
275 std::visit([&oss](
const auto& v) {
276 using T = std::decay_t<
decltype(v)>;
277 if constexpr (std::is_same_v<T, std::string>) {
279 }
else if constexpr (std::is_same_v<T, bool>) {
280 oss << (v ?
"true" :
"false");
281 }
else if constexpr (std::is_same_v<T, int64_t>) {
283 }
else if constexpr (std::is_same_v<T, double>) {
284 oss << std::fixed << std::setprecision(6) << v;
std::string to_string() const
Convert to std::string.
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.
common::interfaces::log_level log_level
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.