venom_log

Crates.iovenom_log
lib.rsvenom_log
version0.1.2
sourcesrc
created_at2022-03-30 09:25:36.029099
updated_at2022-03-31 08:50:12.580483
descriptionRust async log High-performance asynchronous logging
homepagehttps://gitee.com/buddycoder/venom_log
repositoryhttps://gitee.com/buddycoder/venom_log
max_upload_size
id559062
size43,176
BuddyCoder (king0bear)

documentation

https://gitee.com/buddycoder/venom_log

README

venom_log

本程序仿照杰哥的fast_log进行copy!

the fast log . This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

Build Status

一款追求极致速度的日志实现,使用crossbeam 无锁channel提高一倍效率(相对于标准库的mpsc),使用channel异步写日志。完全使用safe 代码实现,无不安全代码

  • 低开销,基于may协程

  • 高性能,使用无锁消息队列,日志先存于队列中,后续flush磁盘。不阻塞调用方

  • 全Append模式写入文件,对固态/机械磁盘效率高(固态以及机械硬盘 顺序写性能好于随机写)

  • 内置 Zip压缩,压缩文件名为日期+序号,无需操心日志文件过大

  • 内置 日志分割,自定义日志满多少条数立即分割

  • 内置 过滤配置支持,可自定义过滤掉其他库打印的日志


              -----------------
log data->    | main channel(crossbeam)  |   ->          
              ----------------- 
                                        ----------------                                    ----------------------
                                  ->    |coroutines channel(may)|  -> background coroutines  |    appender1  |
                                        ----------------                                    ----------------------

                                        ----------------                                    ----------------------
                                  ->    |coroutines channel(may)|  -> background coroutines  |    appender2  |
                                        ----------------                                    ----------------------

                                        ----------------                                    ----------------------
                                  ->    |coroutines channel(may)|  -> background coroutines  |    appender3  |
                                        ----------------                                    ----------------------

                                        ----------------                                    ----------------------
                                  ->    |coroutines channel(may)|  -> background coroutines  |    appender4  |
                                        ----------------                                    ----------------------
  • how to use?
log = "0.4"
venom_log="0.1"

use log 简单日志

use venom_log::{init};
use log::{error, info, warn};
fn  main(){
    let log = venom_log::init(Config::new().console()).unwrap();
    log::info!("Commencing yak shaving{}", 0);
    info!("Commencing yak shaving");
}
split log 分割日志,allow_zip_compress = Zip压缩
#[test]
use venom_log::plugin::file_split::RollingType;
use venom_log::consts::LogSize;
use venom_log::plugin::packer::LogPacker;

#[test]
pub fn test_file_compation() {
    venom_log::init(Config::new()
        .console()
        .file_split("target/logs/",
                    LogSize::MB(1),
                    RollingType::All,
                    LogPacker{})).unwrap();
    for _ in 0..200000 {
        info!("Commencing yak shaving");
    }
    sleep(Duration::from_secs(1));
}
custom log 自定义日志
use venom_log::{LogAppender};
use log::{error, info, warn};

pub struct CustomLog{}
impl LogAppender for CustomLog{
    fn do_log(&mut self, record: &VenomLogRecord) {
        print!("{}",record);
    }
}
fn  main(){
    let wait = venom_log::init(Config::new().custom(CustomLog {})).unwrap();
    info!("Commencing yak shaving");
    sleep(std::time::Duration::from_secs(1));
}
Commit count: 0

cargo fmt