Skip to content

Commit

Permalink
fix loop
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed May 21, 2022
1 parent ae8da87 commit 0aaca23
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [

[package]
name = "fast_log"
version = "1.5.11"
version = "1.5.12"
description = "Rust async log High-performance asynchronous logging"
readme = "Readme.md"
authors = ["ce <[email protected]>"]
Expand Down
53 changes: 33 additions & 20 deletions src/plugin/file_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,33 +233,46 @@ impl LogAppender for FileSplitAppender {
data.send_pack();
}
//if temp_bytes is full,must send pack
let mut temp_log = String::with_capacity(records.len() * 100);
for x in records {
match x.command {
Command::CommandRecord => {}
Command::CommandExit => {}
Command::CommandFlush(_) => {
data.send_pack();
let mut temp_log = {
let mut limit = data.max_split_bytes - data.temp_bytes;
let mut temp = String::with_capacity(limit);
for x in records {
match x.command {
Command::CommandRecord => {
if ((temp.as_bytes().len() + x.formated.as_bytes().len())) < limit {
temp.push_str(&x.formated);
} else {
//do pack
data.file.write(temp.as_bytes());
data.send_pack();
limit = data.max_split_bytes;
temp.clear();
temp.push_str(&x.formated);
}
}
Command::CommandExit => {}
Command::CommandFlush(_) => {}
}
}
temp_log.push_str(&x.formated);
if data.temp_bytes >= data.max_split_bytes {
data.file.write(temp_log.as_bytes());
temp_log.clear();
temp
};
if !temp_log.is_empty() {
if (data.temp_bytes + temp_log.as_bytes().len()) > data.max_split_bytes {
data.send_pack();
}
data.temp_bytes += {
temp_log.as_bytes().len()
let bytes = temp_log.as_bytes();
let w = data.file.write(bytes);
if let Ok(w) = w {
w
} else {
0
}
};
}
data.temp_bytes += {
let w = data.file.write(temp_log.as_bytes());
if let Ok(w) = w {
w
}else{
0
if data.temp_bytes > data.max_split_bytes {
data.send_pack();
}
};
}
}

fn do_log(&self, record: &FastLogRecord) {
Expand Down

0 comments on commit 0aaca23

Please sign in to comment.