27#ifndef PROTOCORE_LOG_H
28#define PROTOCORE_LOG_H
36struct protocore_field;
51#define PROTOCORE_LOG_DISCARD(spec, v, nv) \
54 (void)sizeof(protocore_log_discard_args((spec), (v), (nv))); \
61 const struct protocore_field *
spec;
62 const struct protocore_fval *
v;
94 void (*
const emit)(uint8_t *work);
95 void (*
const set_sink)(uint8_t *work);
107static const LogNs Log __attribute__((unused)) = {
124#define PROTOCORE_LOG_EMIT(lvl, spec_, v_, nv_) \
127 LogV.frame.level = (lvl); \
128 LogV.frame.spec = (spec_); \
129 LogV.frame.v = (v_); \
130 LogV.frame.nv = (nv_); \
131 Log.emit(protocore_log_span()); \
134#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_DEBUG
135#define PROTOCORE_LOGD(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_DEBUG, (spec), (v), (nv))
137#define PROTOCORE_LOGD(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
140#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_INFO
141#define PROTOCORE_LOGI(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_INFO, (spec), (v), (nv))
143#define PROTOCORE_LOGI(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
146#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_WARN
147#define PROTOCORE_LOGW(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_WARN, (spec), (v), (nv))
149#define PROTOCORE_LOGW(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
152#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_ERROR
153#define PROTOCORE_LOGE(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_ERROR, (spec), (v), (nv))
155#define PROTOCORE_LOGE(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
int protocore_log_discard_args(const struct protocore_field *spec, const struct protocore_fval *v, size_t nv)
Declared, never defined: only ever named inside sizeof, so no call is ever generated.
void protocore_log_set_sink(uint8_t *work)
void(* protocore_log_sink_fn)(uint8_t level, const char *line)
Receives an emitted line, already formatted. level is a PROTOCORE_LOG_LEVEL_* value.
uint8_t * protocore_log_span(void)
The PROTOCORE_LOG_BORROW bytes this module's state lives in.
void protocore_log_emit(uint8_t *work)
LogVars LogV
The operands and the outcome.
One line to emit: its level, and the spec that shapes it.
const struct protocore_field * spec
the shape of the message
const struct protocore_fval * v
the values that fill it
uint8_t level
the severity the line carries
void(*const emit)(uint8_t *work)
protocore_log_sink_fn sink
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
#define PROTOCORE_END_DECLS