Files
limen/debug_log/debug_log.cpp

29 lines
578 B
C++
Raw Normal View History

#include "debug_log.h"
#include <cstdarg>
#include <cstdio>
#include "ring_buffer.h"
namespace {
constexpr uint16_t LOG_CAP = 32;
ring_buffer<log_entry, LOG_CAP> buf;
} // namespace
void dlog(std::string_view msg) {
buf.push_overwrite(log_entry{static_cast<uint32_t>(time_us_32()), std::string(msg)});
}
void dlogf(const char* fmt, ...) {
char b[128];
va_list args;
va_start(args, fmt);
vsnprintf(b, sizeof(b), fmt, args);
va_end(args);
dlog(b);
}
log_view log_entries() {
return log_view{buf.data.data(), buf.head, LOG_CAP, buf.used()};
}