Skip to main content

Module logging

Module logging 

Source
Expand description

Logging backend: routes the log-04 facade into a static ring buffer which is drained over the USB-CDC connection.

Architecture:

log::info!(...) ─► Logger ─► push_line() ─► CDC ring (4 KiB, drop-oldest)
                                   ▲
                       panic_report (raw, bypasses level filter)

usb.rs class_task: cdc_peek ─► write_packet ─► cdc_commit ─► inv monitor

The ring is a static, allocation-free byte buffer. Producers append formatted lines (oldest bytes are overwritten when full), the single consumer in the USB class task copies chunks out with peek/commit so a cancelled write never loses data.

Structs§

LogRing 🔒
Single-producer/single-consumer byte ring with overwrite-oldest policy.
Logger 🔒
log::Log implementation that formats records into CDC_RING.
State 🔒
Raw ring contents guarded by LogRing’s critical sections.

Constants§

LINE_MAX 🔒
Maximum formatted length of one log line, prefix and newline included.
RING_SIZE 🔒
Total CDC ring capacity in bytes (power of two).

Statics§

CDC_RING 🔒
Global CDC ring: shared by every producer and the USB drain task.
LOGGER 🔒
Static logger instance registered by init.
READY 🔒
Set once init ran; gates embassy-time access (the time driver only starts with esp_rtos::start(), before that Instant::now() would panic).

Functions§

cdc_commit 🔒
Mark the n bytes previously returned by cdc_peek as consumed.
cdc_peek 🔒
Copy as much pending data as fits into out without consuming it.
configured_level 🔒
Map the LOG_LEVEL build env to a max level; unknown values fall back to Info.
drain_snapshot 🔒
Move the ring contents since mark_snapshot_floor into out, dropping the oldest bytes if needed so the newest data always fits. Consumes everything.
init
Initialize the global logger.
level_marker 🔒
One-character level marker used in the line prefix.
mark_snapshot_floor 🔒
Mark the current write position as the earliest byte a panic snapshot may contain, called after the boot-time replay.
push_line 🔒
Format one prefixed line ([<uptime>ms][<marker>] <args>\n) into the CDC ring. Used by the log::Log implementation and by panic_report (which bypasses the log level filter).
push_raw 🔒
Append bytes verbatim to the CDC ring (no prefix, no newline handling).
uptime_ms 🔒
Milliseconds since boot; 0 before the embassy time driver runs.