27#ifndef PROTOCORE_LOG_H
28#define PROTOCORE_LOG_H
30#include "numeros_scribo/numeros_scribo.h"
47#define PROTOCORE_LOG_DISCARD(spec, v, nv) \
50 (void)sizeof(protocore_log_discard_args((spec), (v), (nv))); \
90 void (*
const emit)(
const uint8_t *work);
103static const LogNs Log __attribute__((unused)) = {
120#define PROTOCORE_LOG_EMIT(lvl, spec_, v_, nv_) \
123 LogV.frame.level = (lvl); \
124 LogV.frame.spec = (spec_); \
125 LogV.frame.v = (v_); \
126 LogV.frame.nv = (nv_); \
127 Log.emit(protocore_log_span()); \
130#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_DEBUG
131#define PROTOCORE_LOGD(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_DEBUG, (spec), (v), (nv))
133#define PROTOCORE_LOGD(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
136#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_INFO
137#define PROTOCORE_LOGI(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_INFO, (spec), (v), (nv))
139#define PROTOCORE_LOGI(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
142#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_WARN
143#define PROTOCORE_LOGW(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_WARN, (spec), (v), (nv))
145#define PROTOCORE_LOGW(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
148#if PROTOCORE_LOG_LEVEL <= PROTOCORE_LOG_LEVEL_ERROR
149#define PROTOCORE_LOGE(spec, v, nv) PROTOCORE_LOG_EMIT(PROTOCORE_LOG_LEVEL_ERROR, (spec), (v), (nv))
151#define PROTOCORE_LOGE(spec, v, nv) PROTOCORE_LOG_DISCARD((spec), (v), (nv))
int protocore_log_discard_args(const mmgr_field *spec, const mmgr_fval *v, size_t nv)
Declared, never defined: only ever named inside sizeof, so no call is ever generated.
EMBED_BEGIN_DECLS typedef void(* protocore_log_sink_fn)(uint8_t level, const char *line)
Receives an emitted line, already formatted. level is a PROTOCORE_LOG_LEVEL_* value.
void protocore_log_set_sink(uint8_t *work)
uint8_t * protocore_log_span(void)
The PROTOCORE_LOG_BORROW bytes this module's state lives in.
void protocore_log_emit(const uint8_t *work)
LogVars LogV
The operands and the outcome.
One line to emit: its level, and the spec that shapes it.
const mmgr_field * spec
the shape of the message
const mmgr_fval * v
the values that fill it
uint8_t level
the severity the line carries
void(*const set_sink)(uint8_t *work)
void(*const emit)(const uint8_t *work)
protocore_log_sink_fn sink