diff --git a/example/Cargo.toml b/example/Cargo.toml index 36517b4..021309e 100644 --- a/example/Cargo.toml +++ b/example/Cargo.toml @@ -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"] } diff --git a/example/src/split_log_flush.rs b/example/src/split_log_flush.rs new file mode 100644 index 0000000..0b84779 --- /dev/null +++ b/example/src/split_log_flush.rs @@ -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/") +} \ No newline at end of file diff --git a/example/src/wait_log_finish.rs b/example/src/wait_log.rs similarity index 100% rename from example/src/wait_log_finish.rs rename to example/src/wait_log.rs diff --git a/src/lib.rs b/src/lib.rs index dabbc20..e1bca40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::*; diff --git a/src/plugin/file_split.rs b/src/plugin/file_split.rs index 2af4608..dac580f 100644 --- a/src/plugin/file_split.rs +++ b/src/plugin/file_split.rs @@ -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());