diff --git a/iroha_logger/src/lib.rs b/iroha_logger/src/lib.rs index b759b5a0ad9..008b07eba62 100644 --- a/iroha_logger/src/lib.rs +++ b/iroha_logger/src/lib.rs @@ -27,8 +27,12 @@ pub fn init(configuration: config::LoggerConfiguration) -> Option { + sender: mpsc::UnboundedSender<()>, + sub: S, +} + +impl SenderFilter { + pub fn new(sub: S) -> (impl Subscriber, mpsc::UnboundedReceiver<()>) { + let (sender, receiver) = mpsc::unbounded_channel(); + (EventSubscriber(Self { sender, sub }), receiver) + } +} + +impl EventInspectorTrait for SenderFilter { + type Subscriber = S; + + fn inner_subscriber(&self) -> &Self::Subscriber { + &self.sub + } + + fn event(&self, event: &Event<'_>) { + self.sender.send(()).unwrap(); + self.sub.event(event) + } +} + +#[tokio::test] +async fn test() { + let (sub, mut rcv) = SenderFilter::new( + tracing_subscriber::fmt() + .with_max_level(tracing_subscriber::filter::LevelFilter::TRACE) + .finish(), + ); + let sub = LevelFilter::new(Level::DEBUG, sub); + tracing::subscriber::set_global_default(sub).unwrap(); + + trace!(a = 2, c = true); + debug!(a = 2, c = true); + info!(a = 2, c = true); + + time::timeout(Duration::from_millis(10), rcv.recv()) + .await + .unwrap() + .unwrap(); + time::timeout(Duration::from_millis(10), rcv.recv()) + .await + .unwrap() + .unwrap(); + assert!(time::timeout(Duration::from_millis(10), rcv.recv()) + .await + .is_err()); +} diff --git a/iroha_macro/iroha_derive/tests/from_variant/03-container-enums.rs b/iroha_macro/iroha_derive/tests/from_variant/03-container-enums.rs index 6ac7d720a7e..4dd0aaeb2e8 100644 --- a/iroha_macro/iroha_derive/tests/from_variant/03-container-enums.rs +++ b/iroha_macro/iroha_derive/tests/from_variant/03-container-enums.rs @@ -1,6 +1,8 @@ -use std::cell::{Cell, RefCell}; -use std::rc::Rc; -use std::sync::{Arc, Mutex, RwLock}; +use std::{ + cell::{Cell, RefCell}, + rc::Rc, + sync::{Arc, Mutex, RwLock}, +}; struct Variant1; struct Variant2; diff --git a/iroha_macro/iroha_derive/tests/from_variant/04-container-from.stderr b/iroha_macro/iroha_derive/tests/from_variant/04-container-from.stderr index aa15ef443de..2ee153cd1df 100644 --- a/iroha_macro/iroha_derive/tests/from_variant/04-container-from.stderr +++ b/iroha_macro/iroha_derive/tests/from_variant/04-container-from.stderr @@ -1,7 +1,7 @@ error[E0119]: conflicting implementations of trait `std::convert::From` for type `Enum` - --> $DIR/03-container-enums.rs:14:10 + --> $DIR/03-container-enums.rs:16:10 | -14 | #[derive(iroha_derive::FromVariant)] +16 | #[derive(iroha_derive::FromVariant)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Enum` | ::: $WORKSPACE/iroha_macro/iroha_derive/tests/from_variant/04-container-from.rs