1 Star 1 Fork 0

BuddyCoder/venom_log

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
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));
}

Empty file

About

基于Rust语言开发的lib. 使用单线程的方式,将日志分别输出到控制台或者日志文件中。 下一个版本考虑增加日志传输第三方日志存储服务中。 expand collapse
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/buddycoder/venom_log.git
git@gitee.com:buddycoder/venom_log.git
buddycoder
venom_log
venom_log
master

Search