11#if DETWS_ENABLE_LOGBUF
27 uint8_t trap_threshold = 0xFF;
28 detws_log_trap_fn trap =
nullptr;
32char level_letter(uint8_t level)
36 case DetwsLogLevel::DETWS_LOG_ERROR:
38 case DetwsLogLevel::DETWS_LOG_WARN:
40 case DetwsLogLevel::DETWS_LOG_INFO:
48void detws_logbuf_reset(
void)
54void detws_log(uint8_t level,
const char *msg)
67 snprintf(s_log.lines[slot],
DETWS_LOG_LINE_LEN,
"%c %s", level_letter(level), msg ? msg :
"");
68 s_log.level[slot] = level;
70 if (s_log.trap && level >= s_log.trap_threshold)
71 s_log.trap(level, s_log.lines[slot]);
74uint16_t detws_log_count(
void)
79const char *detws_log_at(uint16_t i)
86int detws_log_dump(
char *out,
size_t cap)
92 for (uint16_t i = 0; i < s_log.count; i++)
95 size_t n = strnlen(line, cap);
96 size_t need = n + (i + 1 < s_log.count ? 1 : 0);
97 if (pos + need >= cap)
102 memcpy(out + pos, line, n);
104 if (i + 1 < s_log.count)
111void detws_log_set_trap(uint8_t threshold, detws_log_trap_fn cb)
113 s_log.trap_threshold = threshold;
#define DETWS_LOG_LINE_LEN
Maximum length of one stored log line (bytes, including null).
#define DETWS_LOG_LINES
Number of log lines retained in the ring.
Fixed-RAM rotating log buffer with severity traps (DETWS_ENABLE_LOGBUF).