Skip to main content

the_code_graph_cli/
logging.rs

1use tracing_subscriber::EnvFilter;
2
3pub fn init_logging(verbose: u8, debug: bool) {
4    let level = if debug || verbose >= 2 {
5        "debug"
6    } else if verbose == 1 {
7        "info"
8    } else {
9        "warn"
10    };
11
12    let filter =
13        EnvFilter::try_from_env("CODE_GRAPH_LOG").unwrap_or_else(|_| EnvFilter::new(level));
14
15    tracing_subscriber::fmt()
16        .with_env_filter(filter)
17        .with_writer(std::io::stderr)
18        .compact()
19        .without_time()
20        .init();
21}
22
23#[cfg(test)]
24mod tests {
25    #[test]
26    fn init_logging_does_not_panic() {
27        // Can only init once per process, so just verify the function exists
28        // and the level mapping logic works
29        let _ = super::init_logging;
30    }
31}