Skip to content

Commit

Permalink
optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 27, 2024
1 parent 0cdb688 commit ed32184
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 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.7.1"
version = "1.7.2"
description = "Rust async log High-performance asynchronous logging"
readme = "Readme.md"
authors = ["ce <[email protected]>"]
Expand Down
9 changes: 8 additions & 1 deletion src/plugin/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ impl LogAppender for ConsoleAppender {
if records.len() == 0 {
return;
}
let mut buffer = String::with_capacity(records.len());
let mut cap = 0;
if records.len() != 0 {
cap = 0;
for x in records {
cap += x.formated.len();
}
}
let mut buffer = String::with_capacity(cap);
for x in records {
buffer.push_str(&x.formated);
}
Expand Down
9 changes: 8 additions & 1 deletion src/plugin/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ impl FileAppender {
impl LogAppender for FileAppender {
fn do_logs(&mut self, records: &[FastLogRecord]) {
let mut log_file = self.file.borrow_mut();
let mut buf = String::new();
let mut cap = 0;
if records.len() != 0 {
cap = 0;
for x in records {
cap += x.formated.len();
}
}
let mut buf = String::with_capacity(cap);
for x in records {
buf.push_str(&x.formated);
match &x.command {
Expand Down
9 changes: 8 additions & 1 deletion src/plugin/file_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,14 @@ impl Keep for KeepType {
impl LogAppender for FileSplitAppender {
fn do_logs(&mut self, records: &[FastLogRecord]) {
//if temp_bytes is full,must send pack
let mut temp = String::with_capacity(records.len() * 10);
let mut cap = 0;
if records.len() != 0 {
cap = 0;
for x in records {
cap += x.formated.len();
}
}
let mut temp = String::with_capacity(cap);
for x in records {
match x.command {
Command::CommandRecord => {
Expand Down

0 comments on commit ed32184

Please sign in to comment.