rmap/
main.rs

1#![allow(dead_code, unused_imports, unused_variables)]
2// TODO: The CLI surface is still being wired up; silence warnings for helper
3// modules that are not yet invoked by frontends.
4
5use clap::Parser;
6use std::fs::OpenOptions;
7use tracing_appender::non_blocking;
8use tracing_indicatif::IndicatifLayer;
9use tracing_subscriber::{EnvFilter, fmt, prelude::*};
10
11use time;
12use tracing::info;
13
14mod analyze;
15mod commands;
16mod data;
17mod frontends;
18mod loaders;
19mod parsers;
20mod sink;
21mod source;
22
23use frontends::cli::{Cli, Commands};
24
25#[tokio::main]
26async fn main() {
27    let cli = Cli::parse();
28
29    let make_stdout_layer = || {
30        fmt::layer()
31            .with_target(false)
32            .with_span_events(fmt::format::FmtSpan::NONE)
33            .with_timer(fmt::time::LocalTime::new(
34                time::macros::format_description!("[hour]:[minute]:[second]"),
35            ))
36    };
37    let filter_layer = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
38
39    // Add IndicatifLayer for progress bars
40    let indicatif_layer = IndicatifLayer::new();
41
42    let registry = tracing_subscriber::registry()
43        .with(filter_layer)
44        .with(indicatif_layer);
45
46    let mut _file_guard = None;
47
48    if let Some(log_path) = &cli.log {
49        let file = OpenOptions::new()
50            .create(true)
51            .write(true)
52            .truncate(true)
53            .open(log_path)
54            .expect("failed to create log file");
55        let (file_writer, guard) = non_blocking(file);
56        _file_guard = Some(guard);
57
58        let file_layer = fmt::layer()
59            .with_target(false)
60            .with_ansi(false)
61            .with_span_events(fmt::format::FmtSpan::NONE)
62            .with_timer(fmt::time::LocalTime::new(
63                time::macros::format_description!("[hour]:[minute]:[second]"),
64            ))
65            .with_writer(file_writer);
66
67        registry.with(make_stdout_layer()).with(file_layer).init();
68
69        info!("Logging to file: {:?}", log_path);
70    } else {
71        registry.with(make_stdout_layer()).init();
72    }
73
74    cli.command.run().await;
75}