Sharing Several Embedded Software Logging Techniques!

Follow+Star PublicAccount to not miss exciting content

Source | Embedded Miscellaneous

In embedded development, logging and debugging are undoubtedly the most commonly used and practical debugging methods. However, many engineers may not fully leverage the power of logging!

Today, I will share several logging techniques to help you progress from a “printf novice” to a “logging master”!

1. Technique One: Module Tags – Quickly Locate the Source of Problems

1.1 Modular Logging System

Sharing Several Embedded Software Logging Techniques!

1.2 Example

Sharing Several Embedded Software Logging Techniques!

Logging Output Effect:

[WIFI]Starting network scan...
[WIFI]Found 3 networks
[WIFI]Network[0]: MyHome_WiFi, RSSI: -45
[WIFI]Network[1]: Office_5G, RSSI: -67
[WIFI]Network[2]: Guest_Network, RSSI: -78

2. Technique Two: Precise Positioning – When to Log?

2.1 Error Handling

Sharing Several Embedded Software Logging Techniques!

2.2 Critical Operations

Sharing Several Embedded Software Logging Techniques!

2.3 System Startup and Shutdown

Sharing Several Embedded Software Logging Techniques!

2.4 Performance Monitoring

Sharing Several Embedded Software Logging Techniques!

2.5 Communication Logs

Sharing Several Embedded Software Logging Techniques!

2.6 User Behavior

Sharing Several Embedded Software Logging Techniques!

2.7 Branch Execution: Program Flow Tracking

Sharing Several Embedded Software Logging Techniques!

2.8 Crash Information: Fault Scene Protection

Sharing Several Embedded Software Logging Techniques!

3. Technique Three: Logging Switch – Flexibly Control Log Output

3.1 Module-Level Logging Switch

Sharing Several Embedded Software Logging Techniques!

4. Technique Four: Timestamps – Precise Temporal Analysis

4.1 High-Precision Timestamps

Sharing Several Embedded Software Logging Techniques!

4.2 Performance Analysis Logs

Sharing Several Embedded Software Logging Techniques!

5. Technique Five: Log Levels – Hierarchical Information Management

5.1 Standard Log Level Definitions

Sharing Several Embedded Software Logging Techniques!

5.2 Practical Application Examples

Sharing Several Embedded Software Logging Techniques!

6. Technique Six: Unified Format – Structured Log Information

6.1 Standard Log Format Design

Sharing Several Embedded Software Logging Techniques!

Output Effect:

[2024-01-15 14:30:25.123456][INFO][main.c:45][wifi_init] WiFi module initialized
[2024-01-15 14:30:25.234567][DEBUG][sensor.c:128][read_temperature] Temperature: 25.6°C
[2024-01-15 14:30:25.345678][WARN][storage.c:67][save_data] Storage almost full: 95%

7. Technique Seven: Dynamic Filtering – Real-Time Adjustment of Log Output

7.1 Dynamic Filtering Based on EasyLogger

Sharing Several Embedded Software Logging Techniques!

7.2 Command Line Log Control

Sharing Several Embedded Software Logging Techniques!

8. Technique Eight: Smart Switching Between Release/Debug

8.1 Log Control at Compile Time

Sharing Several Embedded Software Logging Techniques!

In Conclusion

A good logging system not only helps you quickly locate problems but also allows you to deeply understand the system’s operational status and even prevent potential issues.

Key Points:

  • Log at critical locations
  • Use module tags for categorization
  • Set log levels reasonably
  • Include precise timestamps
  • Provide dynamic control capabilities

Common Pitfalls to Avoid

  • Excessive Logging: More is not always better
  • Insufficient Information: Lacking critical context
  • Disorganized Format: Difficult to automate processing
  • Performance Neglect: Affects system performance
  • Security Oversight: Leaks sensitive information

———— END ————

Sharing Several Embedded Software Logging Techniques!

How difficult is it to cultivate an excellent embedded engineer?

Sharing Several Embedded Software Logging Techniques!

A/B Partitioning in MCU OTA Upgrades: Classic Solutions and Implementation Logic

Sharing Several Embedded Software Logging Techniques!

Several Popular Embedded Open Source Projects

Leave a Comment