#read #logger #wrap #statistics

read-logger

Wrap Read with a read statistics logger

2 unstable releases

0.2.0 Sep 2, 2023
0.1.0 Sep 2, 2023

#33 in #wrap

Download history 89/week @ 2024-07-20 62/week @ 2024-07-27 160/week @ 2024-08-03 246/week @ 2024-08-10 92/week @ 2024-08-17 161/week @ 2024-08-24 402/week @ 2024-08-31 375/week @ 2024-09-07 143/week @ 2024-09-14 86/week @ 2024-09-21 73/week @ 2024-09-28 51/week @ 2024-10-05 73/week @ 2024-10-12 53/week @ 2024-10-19 43/week @ 2024-10-26 116/week @ 2024-11-02

290 downloads per month
Used in 5 crates (via http-range-client)

MIT/Apache

9KB
142 lines

read-logger

CI build crates.io version docs.rs docs

Wrap Read with a read statistics logger. Implements Read+Seek.

Usage example

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);

Run with (using env_logger):

RUST_LOG=read_logger=debug cargo run

Log output:

[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

Dependencies

~87KB