cargo_auto/
generic_functions_mod.rs1#[allow(dead_code)]
12pub const RED: &str = "\x1b[31m";
13#[allow(dead_code)]
15pub const GREEN: &str = "\x1b[32m";
16#[allow(dead_code)]
18pub const YELLOW: &str = "\x1b[33m";
19#[allow(dead_code)]
21pub const BLUE: &str = "\x1b[34m";
22#[allow(dead_code)]
24pub const RESET: &str = "\x1b[0m";
25pub fn tracing_init() -> anyhow::Result<()> {
31 let offset = time::UtcOffset::current_local_offset()?;
32 let timer = tracing_subscriber::fmt::time::OffsetTime::new(
33 offset,
34 time::macros::format_description!("[hour]:[minute]:[second].[subsecond digits:6]"),
35 );
36
37 let filter = tracing_subscriber::EnvFilter::from_env("CARGO_AUTO_LOG");
46
47 let builder = tracing_subscriber::fmt()
48 .with_file(true)
49 .with_timer(timer)
50 .with_line_number(true)
51 .with_ansi(false)
52 .with_env_filter(filter);
53 if std::env::var("CARGO_AUTO_LOG").is_ok() {
54 let file_appender = tracing_appender::rolling::RollingFileAppender::builder()
56 .rotation(tracing_appender::rolling::Rotation::DAILY)
57 .filename_prefix("cargo_auto")
58 .filename_suffix("log")
59 .build("logs")
60 .expect("initializing rolling file appender failed");
61 builder.with_writer(file_appender).init();
62 } else {
63 builder.init();
64 };
65
66 Ok(())
67}