Skip to content

Commit

Permalink
Improve log sending performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Sep 4, 2022
1 parent f2aa160 commit a6830a6
Show file tree
Hide file tree
Showing 3 changed files with 12 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.5.34"
version = "1.5.35"
description = "Rust async log High-performance asynchronous logging"
readme = "Readme.md"
authors = ["ce <[email protected]>"]
Expand Down
12 changes: 9 additions & 3 deletions src/fast_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::appender::{Command, FastLogRecord};
use crate::config::Config;
use crate::error::LogError;
use crate::filter::Filter;
use crate::{chan, spawn, Receiver, SendError, Sender, WaitGroup, try_send_num};
use crate::{chan, spawn, Receiver, SendError, Sender, WaitGroup, try_send_num, RecvError};
use once_cell::sync::{Lazy, OnceCell};
use std::result::Result::Ok;
use std::sync::Arc;
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Log for Logger {
now: SystemTime::now(),
formated: String::new(),
};
try_send_num(&LOGGER.chan.send,3,fast_log_record);
try_send_num(&LOGGER.chan.send, 3, fast_log_record);
}
}
}
Expand Down Expand Up @@ -180,7 +180,13 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
}
loop {
//recv
let data = LOGGER.chan.recv.recv();
let data = {
if LOGGER.chan.recv.len() == 0 {
LOGGER.chan.recv.recv()
} else {
LOGGER.chan.recv.try_recv().map_err(|e| RecvError {})
}
};
if let Ok(data) = data {
let mut remain;
if LOGGER.chan.recv.len() > 0 {
Expand Down
2 changes: 2 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub type Sender<T> = crossbeam::channel::Sender<T>;
#[cfg(feature = "runtime_thread")]
pub type SendError<T> = crossbeam_channel::SendError<T>;
#[cfg(feature = "runtime_thread")]
pub type RecvError = crossbeam_channel::RecvError;
#[cfg(feature = "runtime_thread")]
pub type JoinHandle<T> = std::thread::JoinHandle<T>;
#[cfg(feature = "runtime_thread")]
pub type WaitGroup = crossbeam_utils::sync::WaitGroup;
Expand Down

0 comments on commit a6830a6

Please sign in to comment.