Skip to content

Commit

Permalink
add impl PackType
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 26, 2024
1 parent 82c1df4 commit 58eac3f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/plugin/file_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait Packer: Send + Sync {
}


pub trait Pack: Send {
pub trait IsPack: Send {
fn need_pack(&mut self, temp_size: usize, arg: &FastLogRecord) -> bool;
}

Expand Down Expand Up @@ -177,7 +177,7 @@ pub enum PackType {
BySize(LogSize),
}

impl Pack for PackType {
impl IsPack for PackType {
fn need_pack(&mut self, temp_size: usize, arg: &FastLogRecord) -> bool {
match self {
PackType::ByDate(date_time) => {
Expand Down Expand Up @@ -207,7 +207,7 @@ pub struct FileSplitAppender {
packer: Arc<Box<dyn Packer>>,
dir_path: String,
sender: Sender<LogPack>,
how_to_pack: Box<dyn Pack>,
is_pack: Box<dyn IsPack>,
//cache data
temp_bytes: AtomicUsize,
temp_name: String,
Expand All @@ -216,7 +216,7 @@ pub struct FileSplitAppender {
impl FileSplitAppender {
pub fn new<F: SplitFile + 'static>(
file_path: &str,
how_to_pack: Box<dyn Pack>,
how_to_pack: Box<dyn IsPack>,
rolling_type: Box<dyn Keep>,
packer: Box<dyn Packer>,
) -> Result<FileSplitAppender, LogError> {
Expand Down Expand Up @@ -260,7 +260,7 @@ impl FileSplitAppender {
dir_path: dir_path.to_string(),
file: Box::new(file) as Box<dyn SplitFile>,
sender,
how_to_pack: how_to_pack,
is_pack: how_to_pack,
temp_name,
packer: arc_packer,
})
Expand Down Expand Up @@ -399,7 +399,7 @@ impl LogAppender for FileSplitAppender {
let current_temp_size = self.temp_bytes.load(Ordering::Relaxed)
+ temp.as_bytes().len()
+ x.formated.as_bytes().len();
if self.how_to_pack.need_pack(current_temp_size, x) {
if self.is_pack.need_pack(current_temp_size, x) {
self.temp_bytes.fetch_add(
{
let w = self.file.write(temp.as_bytes());
Expand All @@ -419,7 +419,7 @@ impl LogAppender for FileSplitAppender {
Command::CommandExit => {}
Command::CommandFlush(ref w) => {
let current_temp_size = self.temp_bytes.load(Ordering::Relaxed);
if self.how_to_pack.need_pack(current_temp_size, x) {
if self.is_pack.need_pack(current_temp_size, x) {
self.temp_bytes.fetch_add(
{
let w = self.file.write(temp.as_bytes());
Expand Down

0 comments on commit 58eac3f

Please sign in to comment.