anchor_chain/nodes/
logger.rs1use crate::error::AnchorChainError;
5use crate::node::Node;
6#[cfg(feature = "tracing")]
7use tracing::instrument;
8
9#[derive(Debug)]
11pub struct Logger<T> {
12 prefix: String,
13 _marker: std::marker::PhantomData<T>,
14}
15
16impl<T> Logger<T> {
17 pub fn new(prefix: String) -> Self {
21 Self {
22 prefix,
23 _marker: std::marker::PhantomData,
24 }
25 }
26}
27
28#[async_trait::async_trait]
29impl<T> Node for Logger<T>
30where
31 T: std::fmt::Debug + Send + Sync,
32{
33 type Input = T;
34 type Output = T;
35
36 #[cfg_attr(feature = "tracing", instrument)]
38 async fn process(&self, input: Self::Input) -> Result<Self::Output, AnchorChainError> {
39 println!("{}: {:?}", self.prefix, input);
40 Ok(input)
41 }
42}
43
44impl<T> Default for Logger<T> {
45 fn default() -> Self {
46 Self {
47 prefix: "Input".to_string(),
48 _marker: std::marker::PhantomData,
49 }
50 }
51}