引入了全面的日志系统,将之前零散的 defmt 使用方式重构为统一、可配置的日志框架。
title: "日志系统重构" date: "2025-10-28"
新增日志模块 (
src/log.rs)- 创建了集中的日志模块,以及带有功能标志控制的日志宏
- 实现条件编译:当日志被禁用时,宏为空操作
- 添加了组件特定的日志宏,可以通过feature来启用和禁用:
os_log- OS 级别操作task_log- 任务管理操作scheduler_log- 调度器操作timer_log- 定时器操作mem_log- 内存管理操作
功能标志
- 新的功能标志:
logs- 启用所有日志功能log-base- 基础日志功能 (defmt, panic-probe, defmt-rtt)log-os- OS 特定日志log-task- 任务特定日志log-mem- 内存特定日志log-timer- 定时器特定日志log-scheduler- 调度器特定日志
- 新的功能标志:
build.rs更改
- 更新 build.rs 以检测和处理新的日志功能标志
- 使用条件编译根据启用的功能包含或排除日志
代码库重构(工作量极大)
- 将所有直接 defmt 使用替换为新的日志宏,之前所有的条件编译不需要了
- 在整个代码库中使用组件特定的宏:
task_log在任务管理代码中 (os_task.rs, executor/mod.rs, 各种二进制文件)timer_log在定时器相关代码中 (timer_queue.rs, os_time/*.rs, time_driver/mod.rs)os_log在 OS 核心操作中 (os_core.rs, bottom_driver/mod.rs, os_cpu.rs)scheduler_log在调度器操作中 (executor/mod.rs, os_cpu.rs)mem_log在内存分配代码中 (arena.rs, stack_allocator.rs)
测试文件优化
- 一些测试文件的函数使用宏生成