use crate::prelude::*;
use std::sync::Arc;
use tracing_subscriber::fmt::MakeWriter;
use tracing_subscriber::fmt::writer::BoxMakeWriter;
#[derive(Clone)]
pub(crate) struct SharedWriter(Arc<BoxMakeWriter>);
impl SharedWriter {
pub(crate) fn new<W>(writer: W) -> Self
where
W: for<'a> MakeWriter<'a> + Send + Sync + 'static,
{
Self::from_box(BoxMakeWriter::new(writer))
}
pub(crate) fn from_box(writer: BoxMakeWriter) -> Self {
Self(Arc::new(writer))
}
}
impl Debug for SharedWriter {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str("SharedWriter(..)")
}
}
impl<'a> MakeWriter<'a> for SharedWriter {
type Writer = <BoxMakeWriter as MakeWriter<'a>>::Writer;
fn make_writer(&'a self) -> Self::Writer {
self.0.make_writer()
}
}