123#define LOG_Broadcast 0x00000001
131#define LOG_Restricted 0x00000002
138#define LOG_Declared 0x00000004
269typedef struct LogRenderCache {
346 LogRenderCache* _cache;
439 _In_opt_
void* userdata);
564 return level <= atomicLoad(int32, &chan->maxlevel, Relaxed);
612#define logStr(level, str) _logStr_##level(LOG_##level, LOG_CHANNEL, LOG_SiteAlways, 0, str)
624#define logStrC(level, chan, str) _logStr_##level(LOG_##level, chan, LOG_SiteAlways, 0, str)
643#define logFmt(level, fmt, ...) _logFmtArgs(level, LOG_CHANNEL, LOG_SiteAlways, 0, fmt, __VA_ARGS__)
656#define logFmtC(level, chan, fmt, ...) _logFmtArgs(level, chan, LOG_SiteAlways, 0, fmt, __VA_ARGS__)
684#define logStrOnce(level, str) _logStr_##level(LOG_##level, LOG_CHANNEL, LOG_SiteOnce, 0, str)
695#define logStrEveryN(level, n, str) \
696 _logStr_##level(LOG_##level, LOG_CHANNEL, LOG_SiteEveryN, (n), str)
707#define logStrEveryT(level, interval, str) \
708 _logStr_##level(LOG_##level, LOG_CHANNEL, LOG_SiteEveryT, (interval), str)
719#define logFmtOnce(level, fmt, ...) \
720 _logFmtArgs(level, LOG_CHANNEL, LOG_SiteOnce, 0, fmt, __VA_ARGS__)
732#define logFmtEveryN(level, n, fmt, ...) \
733 _logFmtArgs(level, LOG_CHANNEL, LOG_SiteEveryN, (n), fmt, __VA_ARGS__)
745#define logFmtEveryT(level, interval, fmt, ...) \
746 _logFmtArgs(level, LOG_CHANNEL, LOG_SiteEveryT, (interval), fmt, __VA_ARGS__)
752#define LOG_CHANNEL LogDefault
755void _logStr(
int level, int64 timestamp, _In_
LogChannel* chan, _In_opt_
const LogSite* site,
757void _logFmt(
int level, int64 timestamp, _In_
LogChannel* chan, _In_opt_
const LogSite* site,
758 _In_ strref fmtstr,
int n, _In_
stvar* args);
762bool _logSiteGate(_Inout_
LogSite* site,
int gate, int64 garg);
764_meta_inline
bool _logSitePasses(_Inout_
LogSite* site,
int level, _In_
LogChannel* chan,
int gate,
774 return logWouldLog(level, chan) && _logSiteGate(site, gate, garg);
781#define _logStrSite(level, chan, gate, garg, str) \
783 static LogSite _log_site; \
784 LogChannel* _log_site_chan = (chan); \
785 if (_logSitePasses(&_log_site, level, _log_site_chan, gate, garg)) \
786 _logStr(level, -1, _log_site_chan, &_log_site, str); \
789#define _logFmtSite(level, chan, gate, garg, fmt, nargs, args) \
791 static LogSite _log_site; \
792 LogChannel* _log_site_chan = (chan); \
793 if (_logSitePasses(&_log_site, level, _log_site_chan, gate, garg)) \
794 _logFmt(level, -1, _log_site_chan, &_log_site, fmt, nargs, args); \
804#define _logFmtArgs(level, chan, gate, garg, fmt, ...) \
805 _logFmt_##level(LOG_##level, \
810 count_macro_args(__VA_ARGS__), \
811 ((stvar[]) { __VA_ARGS__ }))
818#define _logStr_Trace _logStrSite
819#define _logFmt_Trace _logFmtSite
821#define _logStr_Trace(...) ((void)0)
822#define _logFmt_Trace(...) ((void)0)
826#define _logStr_Debug _logStrSite
827#define _logFmt_Debug _logFmtSite
828#define _logStr_DevDiag(level, chan, gate, garg, str) _logStrSite(LOG_Diag, chan, gate, garg, str)
829#define _logFmt_DevDiag(level, chan, gate, garg, fmt, nargs, args) \
830 _logFmtSite(LOG_Diag, chan, gate, garg, fmt, nargs, args)
831#define _logStr_DevVerbose(level, chan, gate, garg, str) \
832 _logStrSite(LOG_Verbose, chan, gate, garg, str)
833#define _logFmt_DevVerbose(level, chan, gate, garg, fmt, nargs, args) \
834 _logFmtSite(LOG_Verbose, chan, gate, garg, fmt, nargs, args)
835#define _logStr_DevInfo(level, chan, gate, garg, str) _logStrSite(LOG_Info, chan, gate, garg, str)
836#define _logFmt_DevInfo(level, chan, gate, garg, fmt, nargs, args) \
837 _logFmtSite(LOG_Info, chan, gate, garg, fmt, nargs, args)
838#define _logStr_DevNotice(level, chan, gate, garg, str) \
839 _logStrSite(LOG_Notice, chan, gate, garg, str)
840#define _logFmt_DevNotice(level, chan, gate, garg, fmt, nargs, args) \
841 _logFmtSite(LOG_Notice, chan, gate, garg, fmt, nargs, args)
842#define _logStr_DevWarn(level, chan, gate, garg, str) _logStrSite(LOG_Warn, chan, gate, garg, str)
843#define _logFmt_DevWarn(level, chan, gate, garg, fmt, nargs, args) \
844 _logFmtSite(LOG_Warn, chan, gate, garg, fmt, nargs, args)
845#define _logStr_DevError(level, chan, gate, garg, str) _logStrSite(LOG_Error, chan, gate, garg, str)
846#define _logFmt_DevError(level, chan, gate, garg, fmt, nargs, args) \
847 _logFmtSite(LOG_Error, chan, gate, garg, fmt, nargs, args)
849#define _logStr_Debug(...) ((void)0)
850#define _logFmt_Debug(...) ((void)0)
851#define _logStr_DevDiag(...) ((void)0)
852#define _logFmt_DevDiag(...) ((void)0)
853#define _logStr_DevVerbose(...) ((void)0)
854#define _logFmt_DevVerbose(...) ((void)0)
855#define _logStr_DevInfo(...) ((void)0)
856#define _logFmt_DevInfo(...) ((void)0)
857#define _logStr_DevNotice(...) ((void)0)
858#define _logFmt_DevNotice(...) ((void)0)
859#define _logStr_DevWarn(...) ((void)0)
860#define _logFmt_DevWarn(...) ((void)0)
861#define _logStr_DevError(...) ((void)0)
862#define _logFmt_DevError(...) ((void)0)
865#define _logStr_Diag _logStrSite
866#define _logFmt_Diag _logFmtSite
867#define _logStr_Verbose _logStrSite
868#define _logFmt_Verbose _logFmtSite
869#define _logStr_Info _logStrSite
870#define _logFmt_Info _logFmtSite
871#define _logStr_Notice _logStrSite
872#define _logFmt_Notice _logFmtSite
873#define _logStr_Warn _logStrSite
874#define _logFmt_Warn _logFmtSite
875#define _logStr_Error _logStrSite
876#define _logFmt_Error _logFmtSite
877#define _logStr_Fatal _logStrSite
878#define _logFmt_Fatal _logFmtSite
LogDest * logRegisterDest(int maxlevel, strref chanfilter, LogDestMsg msgfunc, LogDestBatchDone batchfunc, LogDestClose closefunc, void *userdata)
LogChannel * LogDefault
Default log channel used when no channel is specified.
bool logDestSetFilter(LogDest *dhandle, strref pattern)
LogChannel * logDeclareChan(strref path, flags_t flags)
bool logUnregisterDest(LogDest *dhandle)
void logEnumChans(LogChanEnumCB cb, void *ctx)
LogChannel * logChan(strref path)
strref LogLevelNames[]
Array of log level names as strings (e.g., "Fatal", "Error", etc.)
void logRecordRender(string *out, const LogRecord *rec)
struct LogDest LogDest
Opaque handle to a registered log destination.
strref LogLevelAbbrev[]
Array of single-character log level abbreviations (e.g., "F", "E", etc.)
bool logWouldLog(int level, LogChannel *chan)
void(* LogDestBatchDone)(uint32 batchid, void *userdata)
struct LogCtx LogCtx
Opaque handle to a log context; see logctx.h.
void(* LogDestMsg)(const LogRecord *rec, void *userdata)
bool logDestAddFilter(LogDest *dhandle, strref pattern, bool exclude)
bool logDestSetLevel(LogDest *dhandle, int maxlevel)
void(* LogDestClose)(void *userdata)
bool(* LogChanEnumCB)(LogChannel *chan, void *ctx)
@ LOG_SiteAlways
no rate limiting
@ LOG_SiteEveryN
emit every Nth time this call site is reached
@ LOG_SiteEveryT
emit at most once per interval
@ LOG_SiteOnce
emit only the first time this call site is reached
@ LOG_Notice
Normal but significant conditions.
@ LOG_Debug
Debug messages (compiled out of non-development builds)
@ LOG_Trace
Detailed trace messages (only available in debug builds)
@ LOG_Fatal
Fatal errors, application cannot continue.
@ LOG_Verbose
Detailed informational messages.
@ LOG_Info
Informational messages.
@ LOG_Error
Non-fatal errors requiring attention.
@ LOG_Warn
Warning conditions that may indicate problems.
@ LOG_Diag
Release build diagnostics not normally needed.
#define stvar(typen, val)
Core string types and fundamental operations.
uint32 idx
Stable index into the routing table.
uint32 gatedepth
Depth of the deepest restricted ancestor-or-self.
struct LogChannel * parent
Parent channel, NULL for the root channel.
bool ownring
This channel's ring is its own, not inherited.
string path
Full channel path.
atomic(uint32) sample
Keep one record in N; 0 or 1 is every record.
atomic(uint32) samplecnt
Arrivals so far, for the sampling decision.
flags_t flags
Visibility and policy flags.
uint32 batchid
Opaque batch identifier for grouping related records.
int level
Log severity level (LOG_Fatal, LOG_Error, etc.)
const LogSite * site
Call site identity, or NULL if logged dynamically.
LogChannel * chan
Channel this record was logged to, never NULL.
uint8 hops
How many instances this record has been forwarded through, 0 for a local one.
const stvar * args
Arguments the record was logged with, NULL if none.
strref msgtmpl
Message template, or the literal message when istmpl is false.
int nargs
Number of arguments.
int64 timestamp
Wall clock timestamp when the record was created.
uint64 seq
Increasing sequence number, ordering records across threads.
const LogCtx * ctx
Context in scope when the record was logged, or NULL.
atomic(uint32) last
coarse timestamp of the last emission, in milliseconds
atomic(uint32) count
times a gated call site has been reached
Variant type containers and type-safe variadic argument support.