fast_log
A log implementation for extreme speed, using Crossbeam/channel ,once Batch write logs,fast log date, Appender architecture, appender per thread
- High performance,Low overhead, logs auto merge, Full APPEND mode file writing
- Built-in
ZIP,LZ4compression - Support use
log::logger().flush()method wait to flush disk - Support custom file(impl Trait)
- Support rolling log(
ByDate,BySize,ByDuration) - Support Keep log(
All,KeepTime,KeepNum) Delete old logs,Prevent logs from occupying the disk - uses
#![forbid(unsafe_code)]100% Safe Rust.
-----------------
log data-> | main channel(crossbeam) | ->
-----------------
---------------- ----------------------
-> |thread channel)| -> background thread | appender1 |
---------------- ----------------------
---------------- ----------------------
-> |thread channel)| -> background thread | appender2 |
---------------- ----------------------
---------------- ----------------------
-> |thread channel)| -> background thread | appender3 |
---------------- ----------------------
---------------- ----------------------
-> |thread channel)| -> background thread | appender4 |
---------------- ----------------------
-
How fast is?
-
no flush(chan_len=1000000) benches/log.rs
//MACOS(Apple M1MAX-32GB)
test bench_log ... bench: 85 ns/iter (+/- 1,800)
- all log flush into file(chan_len=1000000) example/bench_test_file.rs
//MACOS(Apple M1MAX-32GB)
test bench_log ... bench: 323 ns/iter (+/- 0)
- how to use?
= "0.4"
= { = "1.7" }
or enable zip/lz4/gzip Compression library
= "0.4"
# "lz4","zip","gzip"
= { = "1.7", = ["lz4", "zip", "gzip"] }
Performance optimization(important)
- use
chan_len(Some(100000))Preallocating channel memory reduces the overhead of memory allocation,for example:
use ;
Use Log(Console)
use ;
Use Log(Console Print)
use ;
Use Log(File)
use ;
use ;
Split Log(ByLogDate)
use Config;
use ;
use sleep;
use Duration;
use LogPacker;
Split Log(ByLogSize)
use Config;
use LogSize;
use ;
use LogPacker;
Custom Log(impl do_log method)
use ;
use Config;
use DateTime;
use Level;