Skip to content

引入了全面的日志系统,将之前零散的 defmt 使用方式重构为统一、可配置的日志框架。

title: "日志系统重构" date: "2025-10-28"

commit

  1. 新增日志模块 (src/log.rs)

    • 创建了集中的日志模块,以及带有功能标志控制的日志宏
    • 实现条件编译:当日志被禁用时,宏为空操作
    • 添加了组件特定的日志宏,可以通过feature来启用和禁用:
      • os_log - OS 级别操作
      • task_log - 任务管理操作
      • scheduler_log - 调度器操作
      • timer_log - 定时器操作
      • mem_log - 内存管理操作
  2. 功能标志

    • 新的功能标志:
      • logs - 启用所有日志功能
      • log-base - 基础日志功能 (defmt, panic-probe, defmt-rtt)
      • log-os - OS 特定日志
      • log-task - 任务特定日志
      • log-mem - 内存特定日志
      • log-timer - 定时器特定日志
      • log-scheduler - 调度器特定日志
  3. build.rs更改

    • 更新 build.rs 以检测和处理新的日志功能标志
    • 使用条件编译根据启用的功能包含或排除日志
  4. 代码库重构(工作量极大)

    • 将所有直接 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)
  5. 测试文件优化

    • 一些测试文件的函数使用宏生成