stream_deck_plugin_template/
logger.rs

1use std::path::Path;
2use std::fs::OpenOptions;
3use std::sync::Arc;
4use tracing_appender::non_blocking::WorkerGuard;
5
6#[derive(Debug, Clone)]
7pub struct Logger {
8    _guard: Arc<WorkerGuard>,
9}
10
11impl Logger {
12    pub fn new(filename: &Path) -> Self {
13        let f = OpenOptions::new()
14            //.write(true)
15            .append(true)
16            .open(filename)
17            .expect("Can open logfile");
18        // :TODO: handle new file creation
19
20        let (non_blocking, guard) = tracing_appender::non_blocking(f);
21        let subscriber = tracing_subscriber::fmt().with_writer(non_blocking);
22        subscriber.init();
23        let _guard = Arc::new(guard);
24        Self { _guard }
25    }
26}