From ac07909d1e96e38aa769fa4b7657018bdb676aa7 Mon Sep 17 00:00:00 2001 From: "zhuxiujia@qq.com" Date: Fri, 28 Jan 2022 20:53:28 +0800 Subject: [PATCH] use lazy replace lazy_static --- example/src/split_log.rs | 10 +++++++--- src/fast_log.rs | 34 +++++++++------------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/example/src/split_log.rs b/example/src/split_log.rs index e00082c..2e06820 100644 --- a/example/src/split_log.rs +++ b/example/src/split_log.rs @@ -14,9 +14,13 @@ fn main(){ Box::new(LogPacker{}), true, ); - for _ in 0..20000 { - log::info!("Commencing yak shaving"); + for _ in 0..12{ + std::thread::spawn(||{ + for _ in 0..2000000 { + log::info!("Commencing yak shaving"); + } + }); } - sleep(Duration::from_secs(3)); + sleep(Duration::from_secs(3*3600*3600)); println!("you can see log files in path: {}","target/logs/") } \ No newline at end of file diff --git a/src/fast_log.rs b/src/fast_log.rs index ed4b1d3..c68344f 100644 --- a/src/fast_log.rs +++ b/src/fast_log.rs @@ -196,33 +196,17 @@ pub fn init_custom_log( } for (recever, appender) in recever_vec { let current_wait_group = wait_group_back.clone(); - if appender.type_name().starts_with("fast_log::plugin") { - // if is file appender, use thread spawn - std::thread::spawn(move || { - loop { - if let Ok(msg) = recever.recv() { - if msg.command.eq(&Command::CommandExit) { - drop(current_wait_group); - break; - } - appender.do_log(msg.as_ref()); + spawn(move || { + loop { + if let Ok(msg) = recever.recv() { + if msg.command.eq(&Command::CommandExit) { + drop(current_wait_group); + break; } + appender.do_log(msg.as_ref()); } - }); - } else { - // if is network appender, use thread spawn - spawn(move || { - loop { - if let Ok(msg) = recever.recv() { - if msg.command.eq(&Command::CommandExit) { - drop(current_wait_group); - break; - } - appender.do_log(msg.as_ref()); - } - } - }); - } + } + }); } loop { //recv