1个稳定版本
| 1.0.0 | 2024年3月21日 |
|---|
#30 在 #log-format
676 每月下载量
在 l0g 中使用
6KB
l0g
针对 no_std 库的具有观点的日志门面,有时也在 std 上下文中使用。
概述
日志功能根据环境不同而有所不同,尤其是在 no_std 和 std 之间。此门面允许将选择使用哪个日志实现的决策委托给顶级应用程序。
任何对 l0g::{error,warn,info,debug,trace} 的调用
- 如果没有设置任何功能,则变为空操作
- 当设置
log功能时,从 log 包中调用log::{error,warn,info,debug,trace} - 当设置
defmt功能时,从 defmt 包中调用defmt::{error,warn,info,debug,trace}
此外,还提供了一个过程宏,以泛化应使用哪种格式化实现
#[l0g::format]
struct MyStruct {
value: u8
}
变为
#[derive(core::fmt::Debug)]
struct MyStruct {
value: u8
}
如果使用 log 功能或
#[derive(defmt::Format)]
struct MyStruct {
value: u8
}
如果使用 defmt 功能。
这允许一个 {:?} 格式化在任何选择的日志实现中都能正常工作。
用法
在你的库的 Cargo.toml 中只需说
l0g = "1"
在顶层应用 no_std 中使用 defmt 功能指定依赖项。有关如何使 defmt 工作的信息,请参阅其相应文档。
l0g = { version = "1", features = ["defmt"] }
在顶层应用 std 中使用 log 功能指定依赖项。有关如何使 log 工作的信息,请参阅其相应文档。
l0g = { version = "1", features = ["log"] }
依赖项
~320–780KB
~18K SLoC