Skip to content

Commit

Permalink
add add_appender
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Mar 9, 2024
1 parent fe77f9a commit 12a5ab0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ impl Config {
}
/// add a custom LogAppender
pub fn custom<Appender: LogAppender + 'static>(self, arg: Appender) -> Self {
self.add_appender(arg)
}

/// add a LogAppender
pub fn add_appender<Appender: LogAppender + 'static>(self, arg: Appender) -> Self {
self.appends.push(Mutex::new(Box::new(arg)));
self
}
Expand Down
2 changes: 2 additions & 0 deletions src/fast_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
19 changes: 12 additions & 7 deletions tests/filter_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 12a5ab0

Please sign in to comment.