This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
LogToQueue is an Arduino library for ESP32 that enables dual-output logging: simultaneously sending log messages to a serial port and a FreeRTOS queue. This allows flexible log handling - logs can be redirected to SD cards, MQTT, alternative serial ports, or any custom destination.
The library extends Arduino's Print class, making it compatible with standard print() and println() methods.
- Architecture: ESP32 only (requires FreeRTOS)
- Framework: Arduino
- Build System: PlatformIO
- Key Dependency: FreeRTOS (for QueueHandle_t)
pio runpio run --target uploadpio run --target monitorpio run --target cleanEdit platformio.ini and change the src_dir line:
src_dir = examples/LogToQueue # or examples/LogToBufferLogToQueue Class (src/LogToQueue.h, src/LogToQueue.cpp)
- Inherits from Arduino's
Printclass - Core method:
write(uint8_t)- handles every character written - Dual output: buffers for serial output, queues for FreeRTOS processing
- Internal buffering (default 256 bytes) prevents memory fragmentation
- Auto-flushes on newline or buffer full
- Buffered Writing: Characters accumulate in an internal buffer until a newline or buffer overflow occurs, then flush to serial port
- Queue Distribution: Every character (including timestamps) is sent to the FreeRTOS queue immediately for parallel processing
- Timestamp Management: When enabled, prepends 13-character timestamp (
HH:MM:SS.mmm) to each line, accounting for it in buffer size calculations
- Default buffer size: 256 bytes
- If timestamp enabled, effective buffer size is reduced by 13 bytes
- Buffer allocation uses
malloc()andrealloc()for dynamic sizing - Buffer flushes automatically when:
- Newline character (
\n) is written - Buffer reaches capacity (prevents overflow)
- Newline character (
Character Flow:
User calls Log.println()
→ write(uint8_t) called for each character
→ If first char of line & timestamp enabled: printTimestamp()
→ Character sent to queue via xQueueSend()
→ Character added to internal buffer
→ On '\n' or buffer full: sendBuffer() flushes to serial
setDump() Toggle:
- Controls whether buffered data is written to serial port
- Queue output always continues regardless of this setting
- Useful for disabling serial output while maintaining queue-based logging
QueueHandle_t queueLog = xQueueCreate(100, sizeof(char));
LogToQueue Log;
Log.begin(&Serial, true, queueLog); // Serial output, timestamp enabled, queue handleTwo patterns demonstrated in examples:
Character-by-character (LogToQueue.ino):
char datoRecibido;
if (xQueueReceive(queueLog, &datoRecibido, 0) == pdTRUE) {
// Process single character
}Line-buffered (LogToBuffer.ino):
while (xQueueReceive(queueLog, &datoRecibido, 0) == pdTRUE) {
if (datoRecibido == '\n') {
// Process complete line in buffer
}
// Build line in buffer
}- Current target:
esp32-S3(ESP32-S3 DevKit M-1) - Flash size: 8MB with custom partition table (
particion8MB.csv) - LittleFS filesystem enabled
- USB CDC on boot enabled for Serial monitoring
- Library visibility: Uses
lib_extra_dirs = .to make local library available to examples
- Version: 1.0.2
- Category: Communication
- ESP32 architecture only
When modifying the library:
- Test with both example sketches (LogToQueue and LogToBuffer)
- Verify timestamp formatting (13 characters exactly)
- Test buffer overflow handling (write more than 256 bytes without newline)
- Validate queue doesn't overflow (adjust queue size in examples if needed)
- Test setDump() toggle functionality
- Monitor for memory leaks in buffer reallocation
- Queue Size: Queue stores individual characters, not strings. Size appropriately (e.g., 100 characters for ~3-5 typical log lines)
- Buffer Size: If changing buffer size with
setBufferSize(), remember timestamp consumes 13 bytes - Character Encoding: Library operates on raw bytes; no UTF-8 handling
- Timestamp Format: Hardcoded 13-character format - changes require updating buffer size logic
The Arduino Library Manager indexing status for this library can be checked at:
https://downloads.arduino.cc/libraries/logs/github.com/hardmax/LogToQueue/
This URL shows whether a new release/version has been picked up and processed by the Arduino indexer.