#log #performance #fast #logging #async

fast_log

Rust async log 高性能异步日志

30 stable releases

1.3.10 Nov 12, 2020
1.3.9 Nov 7, 2020
1.3.2 Oct 30, 2020
1.2.3 Aug 1, 2020
1.0.2 Feb 29, 2020

#245 in Debugging

Download history 57/week @ 2020-08-11 19/week @ 2020-08-18 24/week @ 2020-08-25 39/week @ 2020-09-01 24/week @ 2020-09-08 19/week @ 2020-09-15 29/week @ 2020-09-22 35/week @ 2020-09-29 21/week @ 2020-10-06 22/week @ 2020-10-13 128/week @ 2020-10-20 107/week @ 2020-10-27 173/week @ 2020-11-03 95/week @ 2020-11-10 26/week @ 2020-11-17 62/week @ 2020-11-24

236 downloads per month
Used in rbatis

MIT license

25KB
632 lines

log

the fast log . This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust. 一款追求极致速度的日志实现,使用crossbeam 无锁channel提高一倍效率(相对于标准库的mpsc),使用channel异步写日志。完全使用safe 代码实现,无不安全代码

  • 高性能,使用无锁消息队列,日志先存于队列中,后续flush磁盘。不阻塞调用方
  • 全Append模式写入文件,对固态/机械磁盘效率高(固态以及机械硬盘 顺序写性能好于随机写)
  • 内置 Zip压缩,压缩文件名为日期+序号,无需操心日志文件过大
  • 内置 日志分割,自定义日志满多少条数立即分割
  • 内置 过滤配置支持,可自定义过滤掉其他库打印的日志

              -----------------
log data->    | main channel  |   ->          
              ----------------- 
                                        ----------------             ----------------------
                                  ->    |Thread channel|  -> Thread  |   file   appender  |
                                        ----------------             ----------------------
                                        ----------------             ----------------------
                                  ->    |Thread channel|  -> Thread  |  console  appender  |
                                        ----------------             ----------------------
                                        ----------------             ----------------------
                                  ->    |Thread channel|  -> Thread  |   other   appender  |
                                        ----------------             ----------------------


有多快?

//win10(PC 6核心,机械硬盘)

  • use QPS: 525892 条/s

//win10(PC 6核心,固态硬盘)

  • use QPS: 508215 条/s

support Future mode,async await based on mpsc channel, tokio or async_std support log split,zip_compress

  • how to use?
log = "0.4"
fast_log="1.3"

use log 简单日志

use fast_log::{init_log};
use log::{error, info, warn};
fn  main(){
    fast_log::init_log("requests.log", 1000, log::Level::Info, None,true);      
    info!("Commencing yak shaving");
}
split log 分割日志,allow_zip_compress = Zip压缩
#[test]
    pub fn test_file_compation() {
        fast_log::init_split_log("target/logs/", 1000, 10000, false,log::Level::Info, None, true);
        for _ in 0..200000 {
            info!("Commencing yak shaving");
        }
        sleep(Duration::from_secs(1));
    }
custom log 自定义日志
use fast_log::{init_custom_log,LogAppender};
use log::{error, info, warn};

    pub struct CustomLog{}
    impl LogAppender for CustomLog{
        fn do_log(&mut self, record: &FastLogRecord) {
            print!("{}",record);
        }
    }
fn  main(){
    fast_log::init_custom_log(vec![Box::new(CustomLog {})], 1000, log::Level::Info, Box::new(NoFilter {}));
    info!("Commencing yak shaving");
    std::thread::sleep(std::time::Duration::from_secs(1));
}

Dependencies

~3–4.5MB
~78K SLoC