#read #logger #wrap #statistics #level #file #count

read-logger

用读取统计日志器包装 Read

2 个不稳定版本

0.2.0 2023年9月2日
0.1.0 2023年9月2日

#30#wrap

Download history 34/week @ 2024-04-08 26/week @ 2024-04-15 28/week @ 2024-04-22 45/week @ 2024-04-29 24/week @ 2024-05-06 89/week @ 2024-05-13 126/week @ 2024-05-20 99/week @ 2024-05-27 82/week @ 2024-06-03 37/week @ 2024-06-10 136/week @ 2024-06-17 45/week @ 2024-06-24 43/week @ 2024-07-01 72/week @ 2024-07-08 96/week @ 2024-07-15 97/week @ 2024-07-22

313 每月下载量
5 个 crate 中使用 (通过 http-range-client)

MIT/Apache

9KB
142 代码行数(不包括注释)

read-logger

CI build crates.io version docs.rs docs

用读取统计日志器包装 Read。实现了 Read+Seek

使用示例

use std::fs::File;
use std::io::{BufReader, Read};
use read_logger::{Level, ReadLogger};

let f = File::open("Cargo.toml").unwrap();
let mut read_logger = ReadLogger::new(f, Level::Debug, "READ");
let mut reader = BufReader::new(&mut read_logger);

let mut bytes = [0; 4];
reader.read_exact(&mut bytes).unwrap();
reader.read_exact(&mut bytes).unwrap();

// BufReader does only one read() call:
assert_eq!(read_logger.stats().read_count, 1);
assert!(read_logger.stats().bytes_total > 200);

使用 (使用 env_logger) 运行

RUST_LOG=read_logger=debug cargo run

日志输出

[2023-09-02T18:41:41Z DEBUG read_logger] Initialize Read logger `READ`,tag,begin,end,length,request_length,count,bytes_total
[2023-09-02T18:41:41Z DEBUG read_logger] Read 0-236 (237 bytes). Total requests: 1 (237 bytes),READ,0,236,237,8192,1,237

依赖项

~87KB