Skip to content

Commit

Permalink
add flush method
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Dec 5, 2021
1 parent c8dd8db commit 052e434
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
8 changes: 5 additions & 3 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ path = "src/split_log_lz4.rs"
name = "split_log_gz"
path = "src/split_log_gz.rs"
[[bin]]
name = "wait_log_finish"
path = "src/wait_log_finish.rs"
name = "wait_log"
path = "src/wait_log.rs"
[[bin]]
name = "bench_test"
path = "src/bench_test.rs"

[[bin]]
name = "split_log_flush"
path = "src/split_log_flush.rs"
[dependencies]

log = { version = "0.4", features = ["std"] }
Expand Down
28 changes: 28 additions & 0 deletions example/src/split_log_flush.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use fast_log::consts::LogSize;
use fast_log::plugin::file_split::RollingType;
use fast_log::plugin::packer::{LogPacker};
use std::thread::sleep;
use std::time::Duration;

fn main(){
fast_log::init_split_log(
"target/logs/",
LogSize::MB(1000),
RollingType::All,
log::Level::Info,
None,
Box::new(LogPacker{}),
true,
);
for _ in 0..20000 {
log::info!("Commencing yak shaving");
}
/// Even if the capacity is not reached, a log is forced to save
fast_log::flush();
/// wait save end,or you can use
/// let wait = fast_log::init_split_log(...);
/// wait.wait();
///
may::coroutine::sleep(Duration::from_secs(3));
println!("you can see log files in path: {}","target/logs/")
}
File renamed without changes.
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ pub mod filter;
pub mod plugin;
pub mod wait;

pub use fast_log::init_custom_log;
///init log
pub use fast_log::init_log;
pub use fast_log::init_split_log;
pub use fast_log::*;
1 change: 1 addition & 0 deletions src/plugin/file_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl LogAppender for FileSplitAppender {
let mut data = self.cell.borrow_mut();
if record.command.eq(&Command::CommandFlush) || (data.temp_bytes >= data.max_split_bytes) {
data.send_pack();
return;
}
let mut write_bytes = 0;
let w = data.file.write(record.formated.as_bytes());
Expand Down

0 comments on commit 052e434

Please sign in to comment.