1#ifndef SENSESP_SRC_SENSESP_SYSTEM_LOG_BUFFER_H_
2#define SENSESP_SRC_SENSESP_SYSTEM_LOG_BUFFER_H_
4#include <freertos/FreeRTOS.h>
5#include <freertos/queue.h>
6#include <freertos/semphr.h>
7#include <freertos/task.h>
102 explicit LogBuffer(
size_t max_lines = 100, uint32_t max_age_ms = 2000,
118 void push_line(
const char* text,
size_t length, uint32_t now_ms);
140 static int vprintf_trampoline(
const char* format, va_list args);
144 static void capture_task(
void* arg);
153 void prune_locked(uint32_t now_ms);
156 uint32_t max_age_ms_;
157 size_t max_line_length_;
158 size_t min_headroom_bytes_;
160 std::deque<LogRecord> records_;
161 uint32_t next_seq_ = 0;
162 uint32_t session_id_;
164 int (*previous_vprintf_)(
const char*, va_list) =
nullptr;
168 QueueHandle_t capture_queue_ =
nullptr;
170 SemaphoreHandle_t mutex_;
171 StaticSemaphore_t mutex_buffer_;
Captures ESP_LOGx output into a bounded RAM buffer for the web UI.
void push_line(const char *text, size_t length, uint32_t now_ms)
Append a pre-formatted log line to the buffer.
LogSnapshot snapshot_since(uint32_t since, bool has_since, uint32_t now_ms)
Return retained lines newer than since.
void install()
Install the chained vprintf hook. Call once, early in startup.
size_t size()
Test/inspection helper: current number of retained records.
uint32_t session_id() const
static LogBuffer * instance()
Accessor used by the static vprintf trampoline.
constexpr size_t kLogCaptureQueueDepth
constexpr size_t kLogCaptureMinHeadroomBytes
constexpr UBaseType_t kLogCaptureTaskPriority
constexpr uint32_t kLogCaptureTaskStackSize
constexpr size_t kLogCaptureLineMax
Maximum captured line length, and the size of each queue slot's text.
char text[kLogCaptureLineMax]
A single captured log line.
Result of a snapshot_since() query, ready to serialize for the web UI.
std::vector< std::string > lines