fix some things

This commit is contained in:
nora 2022-02-21 21:09:04 +01:00
parent b67c722c19
commit 6f5fef2f23
9 changed files with 55 additions and 55 deletions

View file

@ -2,49 +2,47 @@
use anyhow::Result;
use std::env;
use tracing::{info_span, Instrument};
use tracing::{info, info_span, Instrument};
#[tokio::main]
async fn main() -> Result<()> {
let mut dashboard = false;
let mut console = false;
for arg in env::args().skip(1) {
match arg.as_str() {
"--dashboard" => dashboard = true,
"--console" => console = true,
"ignore-this-clippy" => eprintln!("yes please"),
_ => {}
}
}
setup_tracing(console);
setup_tracing();
let global_data = amqp_core::GlobalData::default();
if dashboard {
let dashboard_span = info_span!("dashboard");
tokio::task::Builder::new()
.name("dashboard")
.spawn(amqp_dashboard::dashboard(global_data.clone()).instrument(dashboard_span));
tokio::spawn(amqp_dashboard::dashboard(global_data.clone()).instrument(dashboard_span));
}
amqp_transport::do_thing_i_guess(global_data).await
}
fn setup_tracing(console: bool) {
if console {
console_subscriber::init();
fn setup_tracing() {
let rust_log = std::env::var("RUST_LOG");
const DEFAULT_LOG: &str = "hyper=info,debug";
tracing_subscriber::fmt()
.with_level(true)
.with_timer(tracing_subscriber::fmt::time::time())
.with_ansi(true)
.with_thread_names(true)
.with_env_filter(rust_log.clone().unwrap_or_else(|_| DEFAULT_LOG.to_string()))
.init();
if let Ok(rust_log) = rust_log {
info!(%rust_log, "Using custom log level");
} else {
tracing_subscriber::fmt()
.with_level(true)
.with_timer(tracing_subscriber::fmt::time::time())
.with_ansi(true)
.with_thread_names(true)
.with_env_filter(
std::env::var("RUST_LOG")
.unwrap_or_else(|_| "hyper=info,tokio=trace,runtime=trace,debug".to_string()),
)
.init();
info!(%DEFAULT_LOG, "Using default log level");
}
}