Skip to main content

deepseek_rust_cli/
logger.rs

1use std::{fs, path::PathBuf};
2
3use tracing_subscriber::{fmt, prelude::*, EnvFilter};
4
5pub fn init_logger(debug: bool) {
6    let log_dir = PathBuf::from(".deep/logs");
7    let _ = fs::create_dir_all(&log_dir);
8
9    let file_appender = tracing_appender::rolling::never(".deep/logs", "agent.log");
10    let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
11
12    let filter = if debug {
13        EnvFilter::new("debug")
14    } else {
15        EnvFilter::new("info")
16    };
17
18    let file_layer = fmt::layer()
19        .with_writer(non_blocking)
20        .with_ansi(false)
21        .with_target(true)
22        .with_file(true)
23        .with_line_number(true);
24
25    tracing_subscriber::registry()
26        .with(filter)
27        .with(file_layer)
28        .init();
29
30    // Box::leak to keep the guard alive for the duration of the program
31    Box::leak(Box::new(_guard));
32}