feat(main): advanced logger instantiation

This commit is contained in:
xeruf 2024-08-13 21:24:25 +03:00
parent 6d4666c12d
commit 6cb2d47a8d
3 changed files with 19 additions and 3 deletions

1
Cargo.lock generated
View File

@ -961,6 +961,7 @@ dependencies = [
"chrono",
"colog",
"colored",
"env_logger",
"itertools",
"log",
"nostr-sdk",

View File

@ -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"

View File

@ -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);
}
}