From 046ebd06237c653772d19d5371dd8e873251658e Mon Sep 17 00:00:00 2001 From: zxj Date: Sat, 27 Jul 2024 01:18:24 +0800 Subject: [PATCH] add impl split --- src/config.rs | 8 ++++---- src/plugin/file_loop.rs | 6 +++--- src/plugin/file_split.rs | 14 ++++++-------- tests/split_test.rs | 8 ++++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/config.rs b/src/config.rs index cdeafb1..c9126c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -110,10 +110,10 @@ impl Config { how:H ) -> Self { self.appends.push(Mutex::new(Box::new( - FileSplitAppender::new::( + FileSplitAppender::new::( file_path, - how, - rolling_type, + Box::new(how), + Box::new(rolling_type), Box::new(packer), ) .unwrap(), @@ -150,7 +150,7 @@ impl Config { how_pack:H, ) -> Self { self.appends.push(Mutex::new(Box::new( - FileSplitAppender::new::(file_path,how_pack, keeper, Box::new(packer)).unwrap(), + FileSplitAppender::new::(file_path, Box::new(how_pack), Box::new(keeper), Box::new(packer)).unwrap(), ))); self } diff --git a/src/plugin/file_loop.rs b/src/plugin/file_loop.rs index ede3c4d..4417d44 100644 --- a/src/plugin/file_loop.rs +++ b/src/plugin/file_loop.rs @@ -12,10 +12,10 @@ pub struct FileLoopAppender { impl FileLoopAppender { pub fn new(log_file_path: &str, size: LogSize) -> Result { Ok(Self { - file: FileSplitAppender::new::( + file: FileSplitAppender::new::( log_file_path, - HowToPackType::BySize(size), - KeepType::KeepNum(1), + Box::new(HowToPackType::BySize(size)), + Box::new(KeepType::KeepNum(1)), Box::new(LogPacker {}), )?, }) diff --git a/src/plugin/file_split.rs b/src/plugin/file_split.rs index 3472e8b..9b8ae03 100644 --- a/src/plugin/file_split.rs +++ b/src/plugin/file_split.rs @@ -214,12 +214,10 @@ pub struct FileSplitAppender { } impl FileSplitAppender { - pub fn new( + pub fn new( file_path: &str, - how_to_pack: H, - rolling_type: R, + how_to_pack: Box, + rolling_type: Box, packer: Box, ) -> Result { let temp_name = { @@ -262,7 +260,7 @@ impl FileSplitAppender { dir_path: dir_path.to_string(), file: Box::new(file) as Box, sender, - how_to_pack: Box::new(how_to_pack), + how_to_pack: how_to_pack, temp_name, packer: arc_packer, }) @@ -456,10 +454,10 @@ impl LogAppender for FileSplitAppender { } ///spawn an saver thread to save log file or zip file -fn spawn_saver( +fn spawn_saver( temp_name: String, r: Receiver, - rolling_type: R, + rolling_type: Box, packer: Arc>, ) { std::thread::spawn(move || { diff --git a/tests/split_test.rs b/tests/split_test.rs index 3d7fe28..97f0623 100644 --- a/tests/split_test.rs +++ b/tests/split_test.rs @@ -3,7 +3,7 @@ mod test { use fast_log::appender::{Command, FastLogRecord, LogAppender}; use fast_log::consts::LogSize; use fast_log::plugin::file_name::FileName; - use fast_log::plugin::file_split::{FileSplitAppender, HowToPackType, Keep, Packer, RawFile, RollingType, SplitFile}; + use fast_log::plugin::file_split::{FileSplitAppender, HowToPackType, Keep, Packer, RawFile, RollingType}; use fast_log::plugin::packer::LogPacker; use fastdate::DateTime; use log::Level; @@ -14,10 +14,10 @@ mod test { #[test] fn test_send_pack() { let _ = remove_dir_all("target/test/"); - let mut appender = FileSplitAppender::new::( + let mut appender = FileSplitAppender::new::( "target/test/", - HowToPackType::BySize(LogSize::MB(1)), - RollingType::All, + Box::new(HowToPackType::BySize(LogSize::MB(1))), + Box::new(RollingType::All), Box::new(LogPacker {}), ) .unwrap();