1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
//! Trait for processing logs of a span after it is closed.
//!
//! See [`Processor`] for more details.
use crate::cfg_sync;
use crate::layer::{Tree, TreeLayer};
pub mod blocking;
pub use blocking::BlockingProcessor;
cfg_sync! {
pub mod sync;
pub use sync::AsyncProcessor;
}
/// A type that can process [trace trees][crate::layer::Tree].
///
/// `Processor`s are responsible for both formatting and writing logs to their
/// intended destinations. This is typically implemented using
/// [`Formatter`][crate::formatter::Formatter],
/// [`tracing_subscriber::fmt::MakeWriter`], and [`std::io::Write`].
///
/// This trait is already implemented for
/// [`BlockingProcessor`][blocking::BlockingProcessor] and
/// [`AsyncProcessor`][sync::AsyncProcessor].
pub trait Processor: 'static + Sized {
/// Converts the [`Processor`] into a [`TreeLayer`].
///
/// This is the same as `TreeLayer::new(processor)`.
///
/// # Examples
/// ```
/// # use tracing_forest::processor::Processor;
/// # use tracing_forest::processor::BlockingProcessor;
/// # use tracing_forest::formatter::Pretty;
/// let layer = BlockingProcessor::new(Pretty::new(), std::io::stdout).into_layer();
/// ```
fn into_layer(self) -> TreeLayer<Self> {
TreeLayer::new(self)
}
/// Processes the [`Tree`] of logs. Implementors of this trait are free to
/// define what this means, such as:
/// * Writing to a stdout or a file
/// * Sending over a network
/// * Storing in memory for later access
/// * Ignoring
/// * Or anything else!
fn process(&self, tree: Tree);
}