3 open source libraries commonly used by experts, making MCU development more efficient

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 printfas 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, log4cpphere 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;

6f40e2fc6665e54a2635700f8ddfe998.png
image-20211204142024466

specific usage

log.cYou can integrate the and in the source code log.hinto 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_COLORetc. 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 Log4cand 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.

20f5be4ab0e2e637db344e2ac7738d87.png
color coding

EasyLogger

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

063ef0759fe744db4006d1dcddb22a81.png
TextColor

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...

The university in the header file asks that the C language needs to pay attention to these principles...

7 C programs summarized in actual combat, good things are not hidden

Click on the card above to follow me

4332a0cf7bab8c9a9e968bbe89446d8d.png

Everything you ordered looks good , I take it seriously as I like it

Guess you like

Origin blog.csdn.net/u010632165/article/details/123196402