Ultra-lightweight C logging for embedded systems
microlog is a tiny, portable C logging library for STM32, ESP32, and any other embedded target. Drop in two files, set a macro, and get level-filtered, colour-coded logs over UART, RTT, or your own output channel.
- Six levels:
TRACE·DEBUG·INFO·WARN·ERROR·FATAL - Zero-cost filtering: unneeded levels are compiled away to nothing
- Runtime level control via
microlog_set_level() - Optional ANSI colours make terminal logs readable at a glance
- Optional timestamp (any free-running tick, e.g.
uwTickoresp_timer_get_time) - File + line tracking
- Custom output — swap in your own UART/SWO/RTT function
- No malloc, no static buffers, no external dependencies
- C99 — works with GCC, ARMCC, IAR, Clang
#define MICROLOG_IMPL
#define MICROLOG_COLOR 1
#define MICROLOG_LEVEL MICROLOG_DEBUG
#include "microlog.h"
int main(void) {
log_info("System booted");
log_warn("Voltage dropped to %d mV", 3100);
log_error("I2C timeout on bus %d", 2);
return 0;
}Build & run on desktop:
gcc -I. -DMICROLOG_COLOR=1 -DMICROLOG_LEVEL=0 examples/pc_example.c -o pc_example
./pc_example| Platform | How-to |
|---|---|
| STM32 + HAL | Provide MICROLOG_OUTPUT_FN → wrap HAL_UART_Transmit. See examples/stm32_example.c |
| ESP32 + ESP-IDF | Provide MICROLOG_OUTPUT_FN → call esp_rom_printf. See examples/esp32_example.c |
| Desktop / testing | Use the built-in puts(); nothing to wire. See examples/pc_example.c |
/* Level constants */
MICROLOG_TRACE 0
MICROLOG_DEBUG 1
MICROLOG_INFO 2
MICROLOG_WARN 3
MICROLOG_ERROR 4
MICROLOG_FATAL 5
/* Macros (compile-time filtered by MICROLOG_LEVEL) */
log_trace(...)
log_debug(...)
log_info(...)
log_warn(...)
log_error(...)
log_fatal(...)
/* Runtime control */
void microlog_set_level(int level);
int microlog_get_level(void);Define these before including the header to tailor the library:
| Macro | Default | Effect |
|---|---|---|
MICROLOG_LEVEL |
MICROLOG_INFO |
Minimum level compiled in |
MICROLOG_COLOR |
0 |
Enable ANSI colour output |
MICROLOG_TICK_FN |
unset | uint32_t fn(void) returning a millisecond tick |
MICROLOG_OUTPUT_FN |
puts |
User's output function void fn(const char *s) |
MICROLOG_DISABLE |
0 |
Set to 1 to remove all log code entirely |
microlog/
├── microlog.h API + implementation (define MICROLOG_IMPL once)
├── README.md
├── LICENSE MIT
└── examples/
├── pc_example.c desktop demo
├── stm32_example.c STM32 + HAL_UART
└── esp32_example.c ESP-IDF
MIT