Skip to content

Commit

Permalink
add CanRollingPack
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 27, 2024
1 parent df90d03 commit 664675c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions example/src/bench_test_file_split.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fast_log::bencher::TPS;
use fast_log::config::Config;
use fast_log::consts::LogSize;
use fast_log::plugin::file_split::KeepType;
use fast_log::plugin::file_split::{KeepType, Rolling, RollingType};
use fast_log::plugin::packer::LogPacker;
use std::time::Instant;

Expand All @@ -11,7 +11,7 @@ fn main() {
let _ = std::fs::remove_dir("target/logs/");
fast_log::init(
Config::new()
.file_split("target/logs/", LogSize::MB(1), KeepType::All, LogPacker {})
.file_split("target/logs/", Rolling::new(RollingType::BySize(LogSize::MB(1))),KeepType::All, LogPacker {})
.chan_len(Some(100000)),
)
.unwrap();
Expand Down
16 changes: 10 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ impl Config {
self
}
/// add a FileSplitAppender
pub fn file_split<Packer: Packer + Sync + 'static, Keeper: Keep + 'static, Rolling: CanRollingPack + 'static>(
pub fn file_split<
R: CanRollingPack + 'static,
K: Keep + 'static,
P: Packer + Sync + 'static,
>(
self,
file_path: &str,
rolling: Rolling,
keeper: Keeper,
packer: Packer,
rolling: R,
keeper: K,
packer: P,
) -> Self {
self.appends.push(Mutex::new(Box::new(
FileSplitAppender::new::<RawFile>(
Expand All @@ -127,15 +131,15 @@ impl Config {
/// ```rust
/// use fast_log::Config;
/// use fast_log::consts::LogSize;
/// use fast_log::plugin::file_split::{Rolling, RollingType, RawFile, RollingType};
/// use fast_log::plugin::file_split::{Rolling, RawFile, RollingType, KeepType};
/// use fast_log::plugin::packer::LogPacker;
/// fn new(){
/// fast_log::init(
/// Config::new()
/// .chan_len(Some(100000))
/// .split::<RawFile, _, _, _>(
/// "target/logs/temp.log",
/// RollingType::All,
/// KeepType::All,
/// LogPacker {},
/// Rolling::new(RollingType::BySize(LogSize::MB(1))),
/// ),
Expand Down
6 changes: 3 additions & 3 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, RollingType, Keep, RawFile, RollingType, Rolling};
use fast_log::plugin::file_split::{FileSplitAppender, RollingType, Keep, RawFile, Rolling, KeepType};
use fast_log::plugin::packer::LogPacker;
use fastdate::DateTime;
use log::Level;
Expand All @@ -17,7 +17,7 @@ mod test {
let mut appender = FileSplitAppender::new::<RawFile>(
"target/test/",
Box::new(Rolling::new(RollingType::BySize(LogSize::MB(1)))),
Box::new(RollingType::All),
Box::new(KeepType::All),
Box::new(LogPacker {}),
)
.unwrap();
Expand All @@ -34,7 +34,7 @@ mod test {
}]);
appender.send_pack(appender.temp_name().replace(".log", &DateTime::now().format("YYYY-MM-DDThh-mm-ss.000000.log")), None);
sleep(Duration::from_secs(1));
let rolling_num = RollingType::KeepNum(0).do_keep("target/test/", "temp.log");
let rolling_num = KeepType::KeepNum(0).do_keep("target/test/", "temp.log");
assert_eq!(rolling_num, 1);
let _ = remove_dir_all("target/test/");
}
Expand Down

0 comments on commit 664675c

Please sign in to comment.