diff --git a/Cargo.lock b/Cargo.lock index 60653d0..e4a09a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -901,29 +901,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_filter" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -1415,12 +1392,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "1.5.1" @@ -2319,10 +2290,8 @@ version = "0.1.0" dependencies = [ "clap", "dotenvy", - "env_logger", "flume", "json5", - "log", "notifico-attachment", "notifico-core", "notifico-template", @@ -2331,6 +2300,8 @@ dependencies = [ "serde", "serde_json", "tokio", + "tracing", + "tracing-subscriber", "url", "uuid", ] diff --git a/notifico-core/src/credentials/memory.rs b/notifico-core/src/credentials/memory.rs index 56f1514..1929114 100644 --- a/notifico-core/src/credentials/memory.rs +++ b/notifico-core/src/credentials/memory.rs @@ -3,6 +3,7 @@ use crate::error::EngineError; use async_trait::async_trait; use std::borrow::Cow; use std::collections::HashMap; +use tracing::info; use uuid::Uuid; #[derive(Eq, PartialEq, Hash, Debug)] @@ -16,6 +17,11 @@ pub struct MemoryCredentialStorage(HashMap, RawCredential impl MemoryCredentialStorage { pub fn add_credential(&mut self, project: Uuid, name: String, credential: RawCredential) { + info!( + credential.project = project.to_string(), + credential.name = name, + "Added credential" + ); self.0.insert( CredentialKey { project, diff --git a/notificox/Cargo.toml b/notificox/Cargo.toml index 098f7a1..2d5c638 100644 --- a/notificox/Cargo.toml +++ b/notificox/Cargo.toml @@ -17,7 +17,7 @@ json5 = "0.4.1" flume = "0.11.1" dotenvy = "0.15.7" uuid = { workspace = true } -log = "0.4.22" -env_logger = "0.11.5" url = { workspace = true } reqwest = { workspace = true } +tracing-subscriber = "0.3.19" +tracing = "0.1.41" diff --git a/notificox/src/main.rs b/notificox/src/main.rs index 20b18d5..a63f0f1 100644 --- a/notificox/src/main.rs +++ b/notificox/src/main.rs @@ -1,5 +1,4 @@ use clap::{Parser, Subcommand}; -use log::info; use notifico_attachment::AttachmentPlugin; use notifico_core::contact::RawContact; use notifico_core::credentials::memory::MemoryCredentialStorage; @@ -22,9 +21,15 @@ use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; use tokio::task::JoinSet; +use tracing::info; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{fmt, EnvFilter}; use url::Url; use uuid::Uuid; +const SINGLETON_CREDENTIAL_NAME: &str = "default"; + #[derive(Parser, Debug)] struct Cli { #[command(subcommand)] @@ -66,10 +71,13 @@ async fn main() { let _ = dotenvy::dotenv(); if std::env::var("RUST_LOG").is_err() { - std::env::set_var("RUST_LOG", "notificox=info,warn"); + std::env::set_var("RUST_LOG", "notificox=info,notifico_core=info,warn"); } - env_logger::init(); + tracing_subscriber::registry() + .with(fmt::layer()) + .with(EnvFilter::from_default_env()) + .init(); let cli = Cli::parse(); @@ -90,7 +98,7 @@ async fn main() { let mut credentials = MemoryCredentialStorage::default(); credentials.add_credential( Uuid::nil(), - "notificox".to_string(), + SINGLETON_CREDENTIAL_NAME.to_string(), credential.clone(), ); Arc::new(credentials) @@ -149,16 +157,21 @@ async fn main() { } let transport_name = credential.transport; - let step = SerializedStep( - json!({ "step": transport_registry.get_step(&transport_name).unwrap(), "credential": "notificox" }) - .as_object() - .cloned() - .unwrap(), - ); + let step = json!({ + "step": transport_registry.get_step(&transport_name).unwrap(), + "credential": SINGLETON_CREDENTIAL_NAME + }); + let step = SerializedStep(step.as_object().cloned().unwrap()); pipeline.steps.push(step); + pipeline }; + info!( + "Running pipeline: {}", + serde_json::to_string_pretty(&pipeline).unwrap() + ); + let contacts: Vec = contacts.iter().map(|s| s.parse().unwrap()).collect(); let recipient = Recipient { @@ -174,11 +187,6 @@ async fn main() { context: Default::default(), }; - info!( - "Running pipeline: {}", - serde_json::to_string_pretty(&pipeline).unwrap() - ); - let (pipelines_tx, pipelines_rx) = flume::unbounded(); let pipelines_tx = Arc::new(pipelines_tx);