Skip to content

Commit

Permalink
add impl split
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 26, 2024
1 parent 10e7a04 commit 046ebd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ impl Config {
how:H
) -> Self {
self.appends.push(Mutex::new(Box::new(
FileSplitAppender::new::<RawFile,R,H>(
FileSplitAppender::new::<RawFile>(
file_path,
how,
rolling_type,
Box::new(how),
Box::new(rolling_type),
Box::new(packer),
)
.unwrap(),
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Config {
how_pack:H,
) -> Self {
self.appends.push(Mutex::new(Box::new(
FileSplitAppender::new::<F,R,H>(file_path,how_pack, keeper, Box::new(packer)).unwrap(),
FileSplitAppender::new::<F>(file_path, Box::new(how_pack), Box::new(keeper), Box::new(packer)).unwrap(),
)));
self
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/file_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub struct FileLoopAppender {
impl FileLoopAppender {
pub fn new(log_file_path: &str, size: LogSize) -> Result<FileLoopAppender, LogError> {
Ok(Self {
file: FileSplitAppender::new::<RawFile,KeepType,HowToPackType>(
file: FileSplitAppender::new::<RawFile>(
log_file_path,
HowToPackType::BySize(size),
KeepType::KeepNum(1),
Box::new(HowToPackType::BySize(size)),
Box::new(KeepType::KeepNum(1)),
Box::new(LogPacker {}),
)?,
})
Expand Down
14 changes: 6 additions & 8 deletions src/plugin/file_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,10 @@ pub struct FileSplitAppender {
}

impl FileSplitAppender {
pub fn new<F: SplitFile + 'static,
R: Keep + 'static,
H: HowToPack + 'static>(
pub fn new<F: SplitFile + 'static>(
file_path: &str,
how_to_pack: H,
rolling_type: R,
how_to_pack: Box<dyn HowToPack>,
rolling_type: Box<dyn Keep>,
packer: Box<dyn Packer>,
) -> Result<FileSplitAppender, LogError> {
let temp_name = {
Expand Down Expand Up @@ -262,7 +260,7 @@ impl FileSplitAppender {
dir_path: dir_path.to_string(),
file: Box::new(file) as Box<dyn SplitFile>,
sender,
how_to_pack: Box::new(how_to_pack),
how_to_pack: how_to_pack,
temp_name,
packer: arc_packer,
})
Expand Down Expand Up @@ -456,10 +454,10 @@ impl LogAppender for FileSplitAppender {
}

///spawn an saver thread to save log file or zip file
fn spawn_saver<R: Keep + 'static>(
fn spawn_saver(
temp_name: String,
r: Receiver<LogPack>,
rolling_type: R,
rolling_type: Box<dyn Keep>,
packer: Arc<Box<dyn Packer>>,
) {
std::thread::spawn(move || {
Expand Down
8 changes: 4 additions & 4 deletions tests/split_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,10 +14,10 @@ mod test {
#[test]
fn test_send_pack() {
let _ = remove_dir_all("target/test/");
let mut appender = FileSplitAppender::new::<RawFile, RollingType, HowToPackType>(
let mut appender = FileSplitAppender::new::<RawFile>(
"target/test/",
HowToPackType::BySize(LogSize::MB(1)),
RollingType::All,
Box::new(HowToPackType::BySize(LogSize::MB(1))),
Box::new(RollingType::All),
Box::new(LogPacker {}),
)
.unwrap();
Expand Down

0 comments on commit 046ebd0

Please sign in to comment.