fix: allow tokio tracing to be enabled

fixes https://github.com/scsibug/nostr-rs-relay/issues/48
This commit is contained in:
Greg Heartsfield 2023-01-14 09:47:01 -06:00
parent ba987d3212
commit 0db6487ce3
2 changed files with 12 additions and 9 deletions

View File

@ -18,7 +18,7 @@ description = "A newly created nostr-rs-relay.\n\nCustomize this with your own i
[diagnostics] [diagnostics]
# Enable tokio tracing (for use with tokio-console) # Enable tokio tracing (for use with tokio-console)
#tracing = true #tracing = false
[database] [database]
# Directory for SQLite files. Defaults to the current directory. Can # Directory for SQLite files. Defaults to the current directory. Can

View File

@ -14,22 +14,25 @@ use console_subscriber::ConsoleLayer;
/// Start running a Nostr relay server. /// Start running a Nostr relay server.
fn main() { fn main() {
// configure settings from config.toml
// replace default settings with those read from config.toml
let mut settings = config::Settings::new();
// setup tracing // 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"); info!("Starting up from main");
let args = CLIArgs::parse(); let args = CLIArgs::parse();
// get database directory from args // get database directory from args
let db_dir = args.db; 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 // update with database location
if db_dir.len() > 0 { if db_dir.len() > 0 {
settings.database.data_directory = db_dir; settings.database.data_directory = db_dir;