use sc_observability_types::{LogEvent, ServiceName, v2};
use std::sync::Arc;
pub trait CanonicalLog: Send + Sync {
fn service_name(&self) -> &ServiceName;
fn emit(&self, event: LogEvent) -> Result<(), v2::EventError>;
}
pub type SharedCanonicalLog = Arc<dyn CanonicalLog>;
#[derive(Clone, Debug)]
pub struct NoopCanonicalLog {
service: ServiceName,
}
impl NoopCanonicalLog {
#[must_use]
pub fn new(service_name: ServiceName) -> Self {
Self {
service: service_name,
}
}
#[must_use]
pub fn named_or_default(service: &'static str) -> Self {
let service = ServiceName::new(service).unwrap_or_else(|_| {
ServiceName::new("noop")
.expect("fixed noop identity is valid in pinned sc-observability-types 1.5.0")
});
Self::new(service)
}
}
impl CanonicalLog for NoopCanonicalLog {
fn service_name(&self) -> &ServiceName {
&self.service
}
fn emit(&self, _event: LogEvent) -> Result<(), v2::EventError> {
Ok(())
}
}
#[cfg(feature = "test-util")]
mod test_util;
#[cfg(feature = "test-util")]
pub use test_util::{RecordingCanonicalLog, RejectingCanonicalLog};
#[cfg(test)]
mod tests;