The following article is from Xiaomai Dashi , author Xiaomai DashiLog systems are crucial during system development and debugging, as everyone should be aware. Especially when a project encounters issues, the absence of logs to help locate the problem can be very frustrating.
Since we cannot always step through the program using a debugger, the operational logs of the device become particularly important.
Typically, we have the following requirements for logs:
- Different log levels (
Debug
,Warning
,Info
,Error
,Fatal
); - Log printing should be as simple and easy to use as
printf
; - The ability to set log levels;
- Small footprint;
- Configurable, even allowing logs to be disabled;
- Support for color highlighting based on different log levels;
- Customizable configurations, including timestamps;
- Support for RTOS;
The above are basic functionalities, but in embedded devices, sometimes we want to save the operational logs of the device, and we need the following additional features:
- Support for multiple access methods, such as serial terminal, saving to an embedded file system;
- Support for shell command line access via serial terminal;
Not all of these requirements may be fully implemented.
In addition to the commonly used log4c
and log4cpp
, I would like to recommend three excellent open-source logging libraries that are particularly suitable for microcontroller projects. Starting from lightweight options to more feature-rich ones, the last one is quite powerful, so please be patient and read to the end.
rxi_log
Project address: https://github.com/rxi/log.c
A simple logging library implemented in C99, with the following output:

Usage
Integrate log.c
and log.h
from the source code into your project. To print logs, simply call the following APIs:
log_trace(const char *fmt, ...);log_debug(const char *fmt, ...);log_info(const char *fmt, ...);log_warn(const char *fmt, ...);log_error(const char *fmt, ...);log_fatal(const char *fmt, ...);
In addition to these APIs, there are log_set_quiet
, log_set_lock
, LOG_USE_COLOR
, etc. For more details, please refer to the original project.
ulog
Project address: https://github.com/rdpoor/ulog
uLog provides a structured logging mechanism for embedded microcontrollers or any resource-constrained systems. It inherits some concepts from the popular Log4c
and Log4j
platforms but with lower overhead.
Some features of uLog include:
- uLog is easy to integrate into almost any environment, consisting of a single header file and a source file, and is written in pure C.
- uLog provides familiar severity levels (CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE).
- uLog supports multiple user-defined outputs (console, log files, memory buffers, etc.), each with its own reporting threshold level.
- uLog is “actively independent” with minimal dependencies, requiring only stdio.h, string.h, and stdarg.h.
- When you are not using uLog, it does not interfere with you: if ULOG_ENABLED is not defined at compile time, no logging code will be generated.
- uLog has been well tested. For more details, please refer to the accompanying ulog_test.c file.

EasyLogger
Project address: https://github.com/armink/EasyLogger

I have used this project for a long time and highly recommend it. It is the work of a prominent figure in RT-Thread and has been integrated into the RTOS, supporting a wide range of features that basically meet various development needs.
Features include:
- Lightweight, ROM<1.6K, RAM<0.3K;
- Supports various access modes (e.g., terminal, file, database, serial, 485, Flash…);
- Log content can include level, timestamp, thread information, process information, etc.;
- Thread-safe, and supports asynchronous output and buffered output modes;
- Supports multiple operating systems (RT-Thread, UCOS, Linux, Windows…), and also supports bare-metal platforms;
- Logs support RAW format and hexdump;
- Supports dynamic filtering by tags, levels, and keywords;
- Logs of different levels support different color displays;
- Highly extensible, supporting new features in the form of plugins.
The above is just a part of this project; for more details, please refer to the project address.
Summary
I hope everyone pays attention to the use of logs in their daily development. Set different log levels for each development stage, and set module-specific logs for different modules. This will facilitate locating issues and quickly resolving them, improving efficiency.
Source: Xiaomai Dashi
Copyright belongs to the original author. If there is any infringement, please contact for removal.
Click to read the original text and apply for free.