From 0db6487ce3ec3db60561bee62beb251b0ef50dea Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Sat, 14 Jan 2023 09:47:01 -0600 Subject: [PATCH] fix: allow tokio tracing to be enabled fixes https://github.com/scsibug/nostr-rs-relay/issues/48 --- config.toml | 2 +- src/main.rs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/config.toml b/config.toml index 7e4c02f..c7b0ae9 100644 --- a/config.toml +++ b/config.toml @@ -18,7 +18,7 @@ description = "A newly created nostr-rs-relay.\n\nCustomize this with your own i [diagnostics] # Enable tokio tracing (for use with tokio-console) -#tracing = true +#tracing = false [database] # Directory for SQLite files. Defaults to the current directory. Can diff --git a/src/main.rs b/src/main.rs index 765ef45..c0a97ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,22 +14,25 @@ use console_subscriber::ConsoleLayer; /// Start running a Nostr relay server. fn main() { + // configure settings from config.toml + // replace default settings with those read from config.toml + let mut settings = config::Settings::new(); + // setup tracing - let _trace_sub = tracing_subscriber::fmt::try_init(); + if settings.diagnostics.tracing { + // enable tracing with tokio-console + ConsoleLayer::builder().with_default_env().init(); + } else { + // standard logging + tracing_subscriber::fmt::try_init().unwrap(); + } info!("Starting up from main"); let args = CLIArgs::parse(); // get database directory from args let db_dir = args.db; - // configure settings from config.toml - // replace default settings with those read from config.toml - let mut settings = config::Settings::new(); - if settings.diagnostics.tracing { - // enable tracing with tokio-console - ConsoleLayer::builder().with_default_env().init(); - } // update with database location if db_dir.len() > 0 { settings.database.data_directory = db_dir;