CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
logserializer.h
Go to the documentation of this file.
1#pragma once
4
33
34#include <cx/log/log.h>
35
36CX_C_BEGIN
37
48
63
69typedef void (*LogSerializeFunc)(_Inout_ string* out, _In_ const LogRecord* rec,
70 _In_opt_ void* userdata);
71
73typedef void (*LogSerializerClose)(_In_opt_ void* userdata);
74
81
91 _In_opt_ LogSerializerClose close,
92 _In_opt_ void* userdata);
93
101
107void logSerialize(_Inout_ string* out, _In_opt_ LogSerializer* ser, _In_ const LogRecord* rec);
108
112typedef struct LogTextConfig {
115 uint32 flags;
116
121 strref ctxfields;
123
133_Ret_valid_ LogSerializer* logTextSerializer(_In_opt_ LogTextConfig* config);
134
139
154_Ret_valid_ LogSerializer* logNdjsonSerializer(_In_opt_ LogNdjsonConfig* config);
155
156// ============================================================================
157// Text formatting helpers
158// ============================================================================
159//
160// The pieces the text serializer assembles a line from. Exported so a custom serializer can
161// match its prefixes exactly instead of reimplementing them.
162
171void logVarText(_Inout_ string* out, _In_ const stvar* v);
172
183void logFormatDate(_Inout_ string* out, int dateFormat, uint32 flags, int64 timestamp);
184
190void logFormatLevel(_Inout_ string* out, int level, uint32 flags);
191
197void logFormatChannel(_Inout_ string* out, _In_opt_ LogChannel* chan, uint32 flags);
198
200
201CX_C_END
void(* LogSerializeFunc)(string *out, const LogRecord *rec, void *userdata)
void logSerializerDestroy(LogSerializer **ser)
void logSerialize(string *out, LogSerializer *ser, const LogRecord *rec)
void logVarText(string *out, const stvar *v)
void logFormatChannel(string *out, LogChannel *chan, uint32 flags)
void logFormatLevel(string *out, int level, uint32 flags)
LogSerializer * logNdjsonSerializer(LogNdjsonConfig *config)
LogSerializer * logSerializerCreate(LogSerializeFunc serialize, LogSerializerClose close, void *userdata)
LOG_FLAGS
Formatting flags for text log output.
LogSerializer * logTextSerializer(LogTextConfig *config)
void(* LogSerializerClose)(void *userdata)
Releases a serializer's private context.
LOG_DATE_FORMATS
Timestamp format options for log output.
void logFormatDate(string *out, int dateFormat, uint32 flags, int64 timestamp)
@ LOG_ChannelFirst
Channel between date and level instead of at end.
@ LOG_OmitLevel
Do not include severity level.
@ LOG_BracketChannel
Enclose channel in brackets [net/http].
@ LOG_BracketLevel
Enclose log level in brackets [INFO].
@ LOG_AddColon
Add colon after the prefix.
@ LOG_OmitDate
Do not include a timestamp at all.
@ LOG_IncludeChannel
Include channel path in output.
@ LOG_IncludeContext
Append the log context's fields as [key:value ...].
@ LOG_JustifyLevel
Make level a fixed-width column.
@ LOG_ShortLevel
Use single-character level abbreviations.
@ LOG_LocalTime
Use local time instead of UTC.
@ LOG_DateISO
ISO 8601: "2026-01-02T15:04:05Z", or with a zone offset.
@ LOG_DateTimeOnlyMsec
Time of day only, with milliseconds: "15:04:05.123".
@ LOG_DateSyslog
Syslog format: "Jan 2 15:04:05".
@ LOG_DateISOCompact
Compact ISO: "2026-01-02 15:04:05".
@ LOG_DateISOCompactMsec
Compact ISO with milliseconds: "2026-01-02 15:04:05.123".
@ LOG_DateTimeOnly
Time of day only, no calendar date: "15:04:05".
@ LOG_DateNCSA
NCSA Common Log format: "02/Jan/2026:15:04:05 +00 00".
#define stvar(typen, val)
Definition stvar.h:162
Core logging system API.
Configuration for the NDJSON serializer.
uint32 flags
Bitwise OR of LOG_FLAGS values; only LOG_LocalTime is consulted.
A record serializer, owned by whichever transport it was handed to.
void * userdata
Serializer-private context.
LogSerializeFunc serialize
Called once per record.
LogSerializerClose close
Optional; called when the owning transport closes.
uint32 flags
Bitwise OR of LOG_FLAGS values.
int dateFormat
Date format from LOG_DATE_FORMATS; ignored under LOG_OmitDate.
int spacing
Spaces between the prefix and the message (0 defaults to 2)