diff --git a/Cargo.toml b/Cargo.toml index 2a30b5f..0822498 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ [package] name = "fast_log" -version = "1.6.13" +version = "1.6.14" description = "Rust async log High-performance asynchronous logging" readme = "Readme.md" authors = ["ce "] diff --git a/src/config.rs b/src/config.rs index 295191a..a80db60 100644 --- a/src/config.rs +++ b/src/config.rs @@ -140,6 +140,11 @@ impl Config { } /// add a custom LogAppender pub fn custom(self, arg: Appender) -> Self { + self.add_appender(arg) + } + + /// add a LogAppender + pub fn add_appender(self, arg: Appender) -> Self { self.appends.push(Mutex::new(Box::new(arg))); self } diff --git a/src/fast_log.rs b/src/fast_log.rs index dfed9de..d64af9e 100644 --- a/src/fast_log.rs +++ b/src/fast_log.rs @@ -64,9 +64,11 @@ impl Log for Logger { if let Some(send) = LOGGER.send.get() { for filter in filter.filters.iter() { if !filter.do_log(record) { + println!("no"); return; } } + println!("send"); let _ = send.send(FastLogRecord { command: Command::CommandRecord, level: record.level(), diff --git a/tests/filter_test.rs b/tests/filter_test.rs index 13a1ded..ef38a4d 100644 --- a/tests/filter_test.rs +++ b/tests/filter_test.rs @@ -2,23 +2,28 @@ mod test { use log::LevelFilter; use fast_log::{Config, FastLogFormat}; - use fast_log::appender::{FastLogRecord, LogAppender}; + use fast_log::appender::{Command, FastLogRecord, LogAppender}; use fast_log::filter::ModuleFilter; #[test] fn test_send_pack() { let m = ModuleFilter::new(); m.modules.push(module_path!().to_string()); - pub struct A{} - impl LogAppender for A{ - fn do_logs(&self, _records: &[FastLogRecord]) { - panic!("must be filter log,but do_log"); + pub struct A {} + impl LogAppender for A { + fn do_logs(&self, records: &[FastLogRecord]) { + for x in records { + if x.command == Command::CommandRecord { + panic!("must be filter log,but do_log"); + } + } } } fast_log::init(Config::new() - .console() .format(FastLogFormat::new().set_display_line_level(LevelFilter::Trace)) - .add_filter(m)).unwrap(); + .add_filter(m) + .add_appender(A{}) + ).unwrap(); log::info!("aaa"); log::logger().flush(); }