1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use tracing_appender::non_blocking::WorkerGuard;

pub struct Log;

impl Log {
    pub fn init() -> Result<WorkerGuard, anyhow::Error> {
        let home_dir = dirs::home_dir().unwrap();
        let log_path = home_dir.join(".config/testing_language_server/logs");
        let file_appender = tracing_appender::rolling::daily(log_path, "prefix.log");
        let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
        tracing_subscriber::fmt().with_writer(non_blocking).init();
        Ok(guard)
    }

    pub fn debug(msg: impl std::fmt::Debug) {
        tracing::debug!("{:?}", msg);
    }

    pub fn info(msg: impl std::fmt::Debug) {
        tracing::info!("{:?}", msg);
    }

    pub fn warn(msg: impl std::fmt::Debug) {
        tracing::warn!("{:?}", msg);
    }

    pub fn error(msg: impl std::fmt::Debug) {
        tracing::error!("{:?}", msg);
    }
}