12#ifndef TWD_PRINTF_FORMAT
13#define TWD_PRINTF_FORMAT(fmt, args) __attribute__((format(printf, fmt, args)))
36 void end() { out_ =
nullptr; }
40 if (out) out->flush();
57 void debug(
const char* fmt, ...) TWD_PRINTF_FORMAT(2, 3) {
63 void info(
const char* fmt, ...) TWD_PRINTF_FORMAT(2, 3) {
69 void warning(
const char* fmt, ...) TWD_PRINTF_FORMAT(2, 3) {
75 void error(
const char* fmt, ...) TWD_PRINTF_FORMAT(2, 3) {
85 if (!out ||
level < level_)
return;
86 static constexpr char kPrefix[] =
"[dongle] ? ";
88 size_t len =
sizeof(kPrefix) - 1;
89 memcpy(buf, kPrefix, len);
90 buf[len - 2] =
"DIWE"[(int)
level];
91 int n = vsnprintf(buf + len,
sizeof(buf) - len - 2, fmt, ap);
93 len += (size_t)n <
sizeof(buf) - len - 2 ? (size_t)n :
sizeof(buf) - len - 3;
96 out->write((
const uint8_t*)buf, len);
100 Print*
volatile out_ =
nullptr;
static twd::LoggerClass TWD_LOGGER
The logger used by all components; configure it in the sketch with TWD_LOGGER.begin(Serial).
Printf-style logger with log levels; use the global TWD_LOGGER object.
void error(const char *fmt,...)
void vlog(LogLevel level, const char *fmt, va_list ap)
va_list variant of log().
bool enabled(LogLevel level=LogLevel::Info) const
True if lines of level are written somewhere.
void flush()
Waits until the output has sent what was written (e.g. before a restart).
void setLevel(LogLevel level)
Lowest level that is written.
void warning(const char *fmt,...)
void debug(const char *fmt,...)
void log(LogLevel level, const char *fmt,...)
Formats and writes one line of level; does nothing if that level is not enabled.
LogLevel
Severity of a log line; lines below the level set with begin() are discarded.
void begin(Print &out, LogLevel level=LogLevel::Info)
Lines of level and above are written to out (e.g. Serial); call before starting the dongle.
void info(const char *fmt,...)