Click on "Uncle Wheat" above and select "Top/Star Public Account"
Welfare dry goods, delivered as soon as possible
Hello everyone, I am Wheat, the importance of the log system in the process of system development and adjustment,
Everyone should know that, especially after a problem occurs in the project, it is very painful that there is no log to help locate the problem.
Because we can't always step through the debugger to debug the program, the running log of the device is particularly important.
Usually we have these requirements for logs:
different log levels (
Debug
,Warning
,Info,
Error
,Fatal
);Log printing should be
printf
as easy to use as;Ability to set log level;
Small footprint;
Configurable, even logging can be disabled;
Supports color highlighting based on different log levels;
You can customize the configuration, timestamp;
Support RTOS;
The above are relatively basic functions, but in embedded devices, sometimes we want to save the running log of the device, we need some of the following functions;
Support multiple access methods, such as serial terminal, save to embedded file system;
Support shell command line to access through serial terminal;
Not all of these requirements will be fulfilled.
In addition to the commonly used ones log4c
, log4cpp
here are three very good open source log libraries recommended for you, which are more suitable for use in single-chip projects. From the lightweight at the beginning, to the feature-rich at the back, the last one is very powerful, so please be patient until the end.
rxi_log
project address:https://github.com/rxi/log.c
A simple log library implemented based on C99, the specific output is as follows;
specific usage
log.c
You can integrate the and in the source code log.h
into your project. If you need to print the log, you can call the following API, as shown below;
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. Please see the original project for details.
stake
project address:https://github.com/rdpoor/ulog
uLog provides a structured logging mechanism for embedded microcontrollers or any resource-constrained system. It inherits some of the concepts behind the popular Log4c
and platforms, but with lower overhead.Log4j
Some features of uLog:
uLog is easy to integrate into almost any environment, consists of one header and one 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 file, memory buffer, etc.), each with its own reporting threshold level.
uLog is "positively independent" with minimal dependencies, requiring only stdio.h, string.h, and stdarg.h.
When you don't use uLog, it doesn't get in your way: if ULOG_ENABLED is undefined at compile time, no logging code will be generated.
uLog is well tested. See the accompanying ulog_test.c file for details.
EasyLogger
project address:https://github.com/armink/EasyLogger
I have used this project for a long time, and I strongly recommend it. It is the work of RT-Thread, which has been integrated into RTOS. The supported functions are very rich and basically meet the needs of various development.
Features are as follows:
Weight, ROM <1.6K, RAM <0.3K ;
Support multiple access modes (for example: terminal, file, database, serial port, 485, Flash...);
The log content can include level, timestamp, thread information, process information, etc.;
Thread-safe and supports asynchronous output and buffered output modes;
Support a variety of operating systems (RT-Thread, UCOS, Linux, Windows...), and also support bare metal platforms ;
The log supports RAW format and supports hexdump ;
Support dynamic filtering by tags , levels , keywords ;
Each level of log supports different color display;
It is highly extensible and supports extending new functions in the form of plug-ins.
The above is just a part of this project, you can refer to the project address for details.
summary
I hope that everyone will pay attention to the use of logs in normal development, set different levels of logs in each development stage, and set up module logs for different modules, so as to facilitate locating some problems, solve them quickly, and improve efficiency. The article in this issue is here, see you in the next issue.
—— The End ——
Recommended in the past
Seemingly simple code, but hidden secrets...
How to prevent cracking? MCU encryption technology revealed
I advise you to stop being a traffic slave...
7 C programs summarized in actual combat, good things are not hidden
Click on the card above to follow me
Everything you ordered looks good , I take it seriously as I like it