26 lines
819 B
Rust
26 lines
819 B
Rust
use std::collections::VecDeque;
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use tokio::sync::broadcast;
|
|
use tracing_subscriber::{EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
use crate::log_layer::{AppLogLayer, LogLine};
|
|
|
|
pub struct LoggingHandles {
|
|
pub log_tx: broadcast::Sender<LogLine>,
|
|
pub log_history: Arc<Mutex<VecDeque<LogLine>>>,
|
|
}
|
|
|
|
pub fn init_tracing() -> LoggingHandles {
|
|
let (log_tx, _) = broadcast::channel::<LogLine>(512);
|
|
let log_history = Arc::new(Mutex::new(VecDeque::<LogLine>::new()));
|
|
|
|
tracing_subscriber::registry()
|
|
.with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
|
|
.with(fmt::layer())
|
|
.with(AppLogLayer::new(log_tx.clone(), Arc::clone(&log_history)))
|
|
.init();
|
|
|
|
LoggingHandles { log_tx, log_history }
|
|
}
|