feat: set up tracing

This commit is contained in:
Harsh Shandilya 2023-05-11 13:26:51 +05:30
parent 6c02e4edfd
commit b37ede3442
No known key found for this signature in database
4 changed files with 157 additions and 18 deletions

16
src/logging.rs Normal file
View file

@ -0,0 +1,16 @@
use tracing::dispatcher::SetGlobalDefaultError;
use tracing::subscriber::set_global_default;
use tracing::Level;
use tracing_subscriber::{filter::Targets, fmt, layer::SubscriberExt, registry, Layer};
fn configure_tracing(filter: Targets) -> Result<(), SetGlobalDefaultError> {
let registry = registry();
let stdout_log = fmt::layer().compact();
let subscriber = registry.with(stdout_log.with_filter(filter));
set_global_default(subscriber)
}
pub(crate) fn init() -> Result<(), SetGlobalDefaultError> {
let tracing_filter = Targets::new().with_target("gitice", Level::TRACE);
configure_tracing(tracing_filter)
}

View file

@ -1,5 +1,6 @@
pub(crate) mod cli;
pub(crate) mod git;
pub(crate) mod logging;
pub(crate) mod model;
use clap::Parser;
@ -8,6 +9,7 @@ use git::freeze_repos;
use git::thaw_repos;
fn main() -> anyhow::Result<()> {
logging::init()?;
let opts = Opts::parse();
match opts.subcommand {