Skip to content

Commit

Permalink
use lazy replace lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jan 28, 2022
1 parent ffeed64 commit ac07909
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
10 changes: 7 additions & 3 deletions example/src/split_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
}
34 changes: 9 additions & 25 deletions src/fast_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac07909

Please sign in to comment.