From f9555e377336dfd4ec58891be709c0c3dc1d5901 Mon Sep 17 00:00:00 2001 From: "zhuxiujia@qq.com" Date: Fri, 7 Jan 2022 23:56:36 +0800 Subject: [PATCH] edit path --- Cargo.toml | 4 ++-- src/fast_log.rs | 8 +++----- src/plugin/file_split.rs | 10 +++------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8578a3b..b4129c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ license = "MIT" [features] -default = ["zip"] +default = ["zip","cogo"] gzip = ["flate2"] [dependencies] @@ -28,7 +28,7 @@ crossbeam-utils = "0.8" crossbeam = "0.8" crossbeam-channel = "0.5" parking_lot = "0.11" -cogo = "0.1" +cogo = {version = "0.1", optional = true } zip = { version = "0.5", optional = true } diff --git a/src/fast_log.rs b/src/fast_log.rs index 5051995..239841f 100644 --- a/src/fast_log.rs +++ b/src/fast_log.rs @@ -15,8 +15,6 @@ use std::result::Result::Ok; use std::time::{SystemTime, Duration}; use std::sync::Arc; use std::sync::mpsc::SendError; -use cogo::coroutine::{Builder, yield_now}; -use cogo::go; lazy_static! { static ref LOG_SENDER: RwLock> = RwLock::new(Option::None); @@ -198,13 +196,13 @@ pub fn init_custom_log( } appender.do_log(msg.as_ref()); } else { - yield_now(); + cogo::coroutine::yield_now(); } } }); } else { // if is network appender, use thread spawn - go!(Builder::new().stack_size(2*0x1000),move ||{ + cogo::go!(cogo::coroutine::Builder::new().stack_size(2*0x1000),move ||{ loop{ if let Ok(msg) = recever.recv(){ if msg.command.eq(&Command::CommandExit) { @@ -231,7 +229,7 @@ pub fn init_custom_log( break; } } else { - yield_now(); + cogo::coroutine::yield_now(); } } }); diff --git a/src/plugin/file_split.rs b/src/plugin/file_split.rs index c1c7c30..99641c3 100644 --- a/src/plugin/file_split.rs +++ b/src/plugin/file_split.rs @@ -9,10 +9,6 @@ use crate::appender::{Command, FastLogRecord, LogAppender}; use crate::consts::LogSize; use std::ops::Sub; use std::time::Duration; -use cogo::go; -use cogo::std::sync::mpsc::{Receiver, Sender}; - - use zip::result::ZipResult; use crate::error::LogError; @@ -131,7 +127,7 @@ pub struct FileSplitAppenderData { max_split_bytes: usize, dir_path: String, file: File, - sender: Sender, + sender: cogo::std::sync::mpmc::Sender, rolling_type: RollingType, //cache data temp_bytes: usize, @@ -214,7 +210,7 @@ impl FileSplitAppender { temp_bytes = m.len() as usize; } file.seek(SeekFrom::Start(temp_bytes as u64)); - let (sender, receiver) = cogo::std::sync::mpsc::channel(); + let (sender, receiver) = cogo::chan!(); spawn_saver(file_name,receiver, packer); Self { cell: RefCell::new(FileSplitAppenderData { @@ -248,7 +244,7 @@ impl LogAppender for FileSplitAppender { } ///spawn an saver thread to save log file or zip file -fn spawn_saver(temp_name: &str, r: Receiver, packer: Box) { +fn spawn_saver(temp_name: &str, r: cogo::std::sync::mpmc::Receiver, packer: Box) { let temp = temp_name.to_string(); std::thread::spawn(move || { loop {