Skip to content

Commit

Permalink
add trait Rolling
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Sep 19, 2023
1 parent d858969 commit 47ea9a4
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 94 deletions.
20 changes: 11 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::filter::{Filter, NoFilter};
use crate::plugin::console::ConsoleAppender;
use crate::plugin::file::FileAppender;
use crate::plugin::file_loop::FileLoopAppender;
use crate::plugin::file_split::{FileSplitAppender, Packer, RawFile, RollingType, SplitFile};
use crate::plugin::file_split::{FileSplitAppender, Packer, RawFile, Rolling, SplitFile};
use crate::FastLogFormat;
use dark_std::sync::SyncVec;
use log::LevelFilter;
Expand Down Expand Up @@ -90,16 +90,15 @@ impl Config {
self
}
/// add a FileSplitAppender
pub fn file_split<P: Packer + 'static>(
pub fn file_split<P: Packer + Sync + 'static, R: Rolling + Sync + 'static>(
self,
file_path: &str,
temp_size: LogSize,
rolling_type: RollingType,
rolling_type: R,
packer: P,
) -> Self {
self.appends.push(Mutex::new(Box::new(
FileSplitAppender::<RawFile>::new(file_path, temp_size, rolling_type, Box::new(packer))
.unwrap(),
FileSplitAppender::<RawFile>::new(file_path, temp_size, rolling_type, packer).unwrap(),
)));
self
}
Expand All @@ -118,16 +117,19 @@ impl Config {
// LogPacker {},
// ),
// );
pub fn split<S: SplitFile + 'static, P: Packer + 'static>(
pub fn split<
F: SplitFile + 'static,
R: Rolling + Sync + 'static,
P: Packer + Sync + 'static,
>(
self,
file_path: &str,
temp_size: LogSize,
rolling_type: RollingType,
rolling_type: R,
packer: P,
) -> Self {
self.appends.push(Mutex::new(Box::new(
FileSplitAppender::<S>::new(file_path, temp_size, rolling_type, Box::new(packer))
.unwrap(),
FileSplitAppender::<F>::new(file_path, temp_size, rolling_type, packer).unwrap(),
)));
self
}
Expand Down
8 changes: 4 additions & 4 deletions src/fast_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
sender_vec.push(s);
recever_vec.push((r, a));
}
for (recever, appender) in recever_vec {
for (receiver, appender) in recever_vec {
spawn(move || {
let mut exit = false;
loop {
let mut remain = vec![];
if recever.len() == 0 {
if let Ok(msg) = recever.recv() {
if receiver.len() == 0 {
if let Ok(msg) = receiver.recv() {
remain.push(msg);
}
}
//recv all
loop {
match recever.try_recv() {
match receiver.try_recv() {
Ok(v) => {
remain.push(v);
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/file_loop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::appender::{FastLogRecord, LogAppender};
use crate::consts::LogSize;
use crate::error::LogError;
use crate::plugin::file_split::{FileSplitAppender, RollingType, SplitFile};
use crate::plugin::file_split::{FileSplitAppender, RollingNum, SplitFile};
use crate::plugin::packer::LogPacker;

/// Single logs are stored in rolling mode by capacity
Expand All @@ -15,8 +15,8 @@ impl<F: SplitFile> FileLoopAppender<F> {
file: FileSplitAppender::<F>::new(
log_file_path,
size,
RollingType::KeepNum(1),
Box::new(LogPacker {}),
RollingNum { num: 1 },
LogPacker {},
)?,
})
}
Expand Down
Loading

0 comments on commit 47ea9a4

Please sign in to comment.