17 个版本
0.1.16 | 2022 年 8 月 31 日 |
---|---|
0.1.15 | 2022 年 8 月 29 日 |
361 在 日期和时间
每月 42 次下载
22KB
313 行
这个 crate 用于轻松创建使用 tracing crate 的旋转日志。我打算在每一个项目中使用它,所以它会不断改进。我认为它已经比大多数其他语言的解决方案更好了。它确实有效。但仍然非常初步。
示例
// prelude includes everything you need, including time zones:
use tracing_storage_logger::prelude::*;
fn main() {
// It's going to complain this is an unused variable. That's fine. Use an "_" underscore if you wish:
let logger = Logger::new(
// Root path for all logs would be [project_root]/logs,in this case:
PathBuf::from(r"logs"),
// Size of each file before rotating and adding a date:
ContentLimit::Bytes(1024),
// max number of files to archive for each file name:
4,
chrono_tz::US::Eastern
);
info!(message = "🍺🍺🍺 Cheers!", path = "general");
info!(message = "🌈🌈🌈 Peace and beauty", path = "general");
function_a();
}
#[instrument(level = "trace")]
fn function_a(){
info!(message = "Inside function a", path = "Transactions", level = "error");
function_b();
warn!("Exiting function a");
}
#[instrument(level = "debug")]
fn function_b(){
info!("Inside function b");
function_c("Some message".into());
warn!("Exiting function b");
}
#[instrument]
fn function_c(some_argument: &str){
info!("Inside function c");
error!("Exiting function c");
}
依赖关系
~4–10MB
~95K SLoC