extract debug_log into its own static library; expose log_view iterator instead of raw ring_buffer
This commit is contained in:
28
debug_log/debug_log.cpp
Normal file
28
debug_log/debug_log.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#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()};
|
||||
}
|
||||
Reference in New Issue
Block a user