Home / Learn Embedded C / Logging on Resource-Constrained Devices

Logging on Resource-Constrained Devices

Designing a logging system that fits within a small microcontroller's limited flash, RAM and CPU budget.

In shortDesigning a logging system that fits within a small microcontroller's limited flash, RAM and CPU budget.

What's actually going on

The basic idea

Resource-constrained logging typically favors compact, fixed-format binary log entries over verbose text strings (saving both flash for format strings and runtime CPU for text formatting), stored in a circular buffer in RAM or a small region of flash/EEPROM.

Why this comes up

Full-featured desktop-style logging (rich formatted text strings, unbounded log file growth) is often simply impractical on a small microcontroller's limited flash and RAM — logging design on these devices has to be a deliberate, resource-aware trade-off from the start.

The mechanics

A common pattern logs a small numeric event code plus a few raw data values (rather than a fully formatted string), decoding the human-readable message only later, on a host computer or external tool, which also keeps the compact on-device format decoupled from log-message wording changes.

Where it is used

  • On-device diagnostic logging
  • Resource-budget-conscious design
  • Field diagnostics infrastructure

Try it

Logging a compact numeric event instead of a full formatted stringC: edit and run

A host tool would later decode event_code 1 as "sensor read" and 2 as "UART error", keeping the on-device format compact and format-string-free.

Try it: a circular log buffer that overwrites its oldest entry

Wrapping a fixed-size log buffer instead of growing it unboundedC: edit and run

With only 3 slots and 4 incoming events, the oldest entry (code 5) was overwritten — a deliberate, bounded trade-off appropriate for a small flash/RAM budget.

Quick check

1. Why do resource-constrained devices often log compact numeric event codes instead of full formatted text strings?