nizaam-core 1.0.1

Domain-agnostic Rust infrastructure core for building secure, observable, reliable, and extensible Nizaam engines.
Documentation
use std::sync::Arc;

use super::dispatch::LogDispatcher;
use super::{DispatchError, LogScope, LogSink, LogSource, LoggingInstance};

/// Shared factory and asynchronous dispatcher for structured logging.
pub struct LoggingSystem {
    dispatcher: Arc<LogDispatcher>,
}

impl LoggingSystem {
    pub fn new(capacity: usize) -> Result<Self, DispatchError> {
        Ok(Self {
            dispatcher: LogDispatcher::new(capacity)?,
        })
    }

    pub fn instance(&self, scope: LogScope, source: LogSource) -> LoggingInstance {
        LoggingInstance::new(Arc::clone(&self.dispatcher), scope, source)
    }

    pub fn subscribe(&self, sink: Arc<dyn LogSink>) {
        self.dispatcher.subscribe(sink);
    }

    pub fn shutdown(&self) -> Result<(), DispatchError> {
        self.dispatcher.shutdown()
    }
}