From 6cb2d47a8d8d87fb8e2efba1b3041b183e3da9cf Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 13 Aug 2024 21:24:25 +0300 Subject: [PATCH] feat(main): advanced logger instantiation --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7e0d6c..dd55f44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -961,6 +961,7 @@ dependencies = [ "chrono", "colog", "colored", + "env_logger", "itertools", "log", "nostr-sdk", diff --git a/Cargo.toml b/Cargo.toml index f67a084..702af8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ xdg = "2.5" itertools = "0.12" log = "0.4" chrono = "0.4" +env_logger = "0.11" colog = "1.3" colored = "2.1" nostr-sdk = "0.33" diff --git a/src/main.rs b/src/main.rs index 56d5928..a72b843 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,9 @@ use std::sync::mpsc::Sender; use std::time::Duration; use colored::Colorize; +use env_logger::Builder; use itertools::Itertools; -use log::{debug, error, info, trace, warn}; +use log::{debug, error, info, LevelFilter, trace, warn}; use nostr_sdk::prelude::*; use regex::Regex; use xdg::BaseDirectories; @@ -101,7 +102,20 @@ impl Drop for EventSender { #[tokio::main] async fn main() { - colog::init(); + let mut args = args().skip(1).peekable(); + if args.peek().is_some_and(|arg| arg == "--debug") { + args.next(); + Builder::new() + .filter(None, LevelFilter::Debug) + .filter(Some("mostr"), LevelFilter::Trace) + .parse_default_env() + .init(); + } else { + colog::default_builder() + .filter(Some("nostr-relay-pool"), LevelFilter::Error) + //.filter(Some("nostr-relay-pool::relay::internal"), LevelFilter::Off) + .init(); + } let config_dir = or_print(BaseDirectories::new()) .and_then(|d| or_print(d.create_config_directory("mostr"))) @@ -254,7 +268,7 @@ async fn main() { { let tasks = selected_relay.as_ref().and_then(|url| relays.get_mut(&url)).unwrap_or_else(|| &mut local_tasks); - for argument in args().skip(1) { + for argument in args { tasks.make_task(&argument); } }