CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
logwire.h
Go to the documentation of this file.
1#pragma once
4
46
47#include <cx/buffer/buffer.h>
48#include <cx/container/sarray.h>
49#include <cx/log/log.h>
50#include <cx/log/logctx.h>
51
52CX_C_BEGIN
53
67
74 LOG_WireOmitCtx = 0x00000001,
75};
76
81typedef struct LogWireRecord {
82 int level;
83 strref chanpath;
84 flags_t chanflags;
85 int64 timestamp;
86 uint64 seq;
87 uint32 batchid;
88 uint32 sample;
89 int trigger;
90 uint8 hops;
91 strref origin;
92 strref msgtmpl;
93 bool istmpl;
94 const stvar* args;
95 int nargs;
96 const stvar* ctx;
97 int nctx;
99
104typedef struct LogSubSpec {
107 sa_string patterns;
108
111
116 int64 expiry;
118
120typedef struct LogWireChanInfo {
121 strref path;
122 flags_t flags;
125
135
140typedef struct LogWireGap {
141 uint64 count;
142 uint64 firstseq;
143 uint64 lastseq;
145
156
162typedef bool (*LogWireFrameCB)(_In_ const LogWireFrame* frame, _In_opt_ void* ctx);
163
166
169
179_Ret_valid_ LogWireEncoder* logWireEncoderCreate(_In_opt_ strref origin, flags_t flags);
180
185
200bool logWireEncode(_Inout_ LogWireEncoder* enc, _Inout_ Buffer* out, _In_ const LogRecord* rec);
201
210bool logWireEncodeGap(_Inout_ LogWireEncoder* enc, _Inout_ Buffer* out, uint64 n, uint64 firstseq,
211 uint64 lastseq);
212
230bool logWireEncodeSub(_Inout_ LogWireEncoder* enc, _Inout_ Buffer* out,
231 _In_opt_ const LogSubSpec* spec);
232
240bool logWireEncodeCatalog(_Inout_ LogWireEncoder* enc, _Inout_ Buffer* out,
241 _In_reads_(nchans) const LogWireChanInfo* chans, int nchans);
242
251
256
261
278bool logWireDecode(_Inout_ LogWireDecoder* dec, _In_reads_bytes_(len) const uint8* buf, size_t len,
279 _In_ LogWireFrameCB cb, _In_opt_ void* ctx);
280
294bool logInject(_In_ strref chanpath, _In_ const LogWireRecord* rec);
295
297
298CX_C_END
Simple buffer management.
LogWireDecoder * logWireDecoderCreate(void)
struct LogWireDecoder LogWireDecoder
Opaque decoder; one per connection.
Definition logwire.h:168
LogWireEncoder * logWireEncoderCreate(strref origin, flags_t flags)
struct LogWireEncoder LogWireEncoder
Opaque encoder; one per connection.
Definition logwire.h:165
LOG_WIRE_FLAGS
Encoder options.
Definition logwire.h:69
bool logWireDecode(LogWireDecoder *dec, const uint8 *buf, size_t len, LogWireFrameCB cb, void *ctx)
bool logWireEncodeGap(LogWireEncoder *enc, Buffer *out, uint64 n, uint64 firstseq, uint64 lastseq)
LOG_WIRE_FRAME
Definition logwire.h:58
bool logWireEncode(LogWireEncoder *enc, Buffer *out, const LogRecord *rec)
void logWireDecoderDestroy(LogWireDecoder **dec)
bool logInject(strref chanpath, const LogWireRecord *rec)
void logWireEncoderDestroy(LogWireEncoder **enc)
bool logWireEncodeSub(LogWireEncoder *enc, Buffer *out, const LogSubSpec *spec)
void logWireEndSegment(LogWireEncoder *enc)
bool logWireEncodeCatalog(LogWireEncoder *enc, Buffer *out, _In_reads_(nchans) const LogWireChanInfo *chans, int nchans)
bool(* LogWireFrameCB)(const LogWireFrame *frame, void *ctx)
Definition logwire.h:162
@ LOG_WireOmitCtx
Definition logwire.h:74
@ LOG_WireSiteDecl
Declares a call site's message template, for this segment.
Definition logwire.h:61
@ LOG_WireSubscribe
A receiver asking for a set of channels and levels.
Definition logwire.h:64
@ LOG_WireChanDecl
Declares a channel path and its policy, for this segment.
Definition logwire.h:60
@ LOG_WireCatalog
What a sender is capable of logging.
Definition logwire.h:65
@ LOG_WireEntry
One log record.
Definition logwire.h:62
@ LOG_WireGap
Records that were dropped rather than sent.
Definition logwire.h:63
@ LOG_WireSegment
Opens a segment; everything declared in the old one is forgotten.
Definition logwire.h:59
#define stvar(typen, val)
Definition stvar.h:162
Core logging system API.
Per-thread log context: fields every record on this thread inherits.
Dynamic arrays with type-safe generic programming.
int maxlevel
Most verbose level wanted. A sender clamps this to what it was configured to allow.
Definition logwire.h:110
int64 expiry
Definition logwire.h:116
sa_string patterns
Definition logwire.h:107
const LogWireChanInfo * chans
Channels the sender has interned.
Definition logwire.h:132
int nchans
Number of channels.
Definition logwire.h:133
One channel in a sender's catalog.
Definition logwire.h:120
flags_t flags
Policy flags at the sender (LOG_Restricted, LOG_Broadcast, ...)
Definition logwire.h:122
strref path
Channel path.
Definition logwire.h:121
int maxlevel
Most verbose level anything at the sender currently wants on it.
Definition logwire.h:123
int kind
LOG_WIRE_FRAME.
Definition logwire.h:150
const LogWireGap * gap
LOG_WireGap.
Definition logwire.h:152
const LogSubSpec * sub
LOG_WireSubscribe.
Definition logwire.h:153
const LogWireCatalog * cat
LOG_WireCatalog.
Definition logwire.h:154
const LogWireRecord * rec
LOG_WireEntry.
Definition logwire.h:151
uint64 count
How many records were dropped.
Definition logwire.h:141
uint64 firstseq
Sequence number of the first one.
Definition logwire.h:142
uint64 lastseq
Sequence number of the last one.
Definition logwire.h:143
int level
Severity the sender logged it at.
Definition logwire.h:82
strref chanpath
Channel path the sender logged it to.
Definition logwire.h:83
int nargs
Number of arguments.
Definition logwire.h:95
uint8 hops
Instances it has already been forwarded through.
Definition logwire.h:90
int trigger
Severity that released it from a retention ring, or -1.
Definition logwire.h:89
int nctx
Number of context fields.
Definition logwire.h:97
uint64 seq
Sender's sequence number.
Definition logwire.h:86
int64 timestamp
Sender's wall clock timestamp; never re-stamped on the way in.
Definition logwire.h:85
strref msgtmpl
Message template, or the literal message when istmpl is false.
Definition logwire.h:92
const stvar * args
Arguments, unkeyed ones first in their original order.
Definition logwire.h:94
bool istmpl
msgtmpl is a format template rather than a literal message
Definition logwire.h:93
const stvar * ctx
Context fields that were in scope at the sender, all keyed.
Definition logwire.h:96
flags_t chanflags
The channel's policy flags at the sender (LOG_Restricted etc.)
Definition logwire.h:84
uint32 batchid
Sender's batch id.
Definition logwire.h:87
strref origin
Instance it was originally logged on.
Definition logwire.h:91
uint32 sample
Sampling rate this record survived at the sender.
Definition logwire.h:88