diff --git a/server/src/main.rs b/server/src/main.rs index 2a8573f..13ea8bc 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -22,34 +22,42 @@ use user_handler::UserHandler; // #[tokio::main(flavor = "current_thread")] #[tokio::main] async fn main() -> Result<()> { - // stuff for logging - tracing_subscriber::registry() - .with( - tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { - "server=trace,tower_http=trace,lib=trace".into() - // "server=trace,tower_http=trace,lib=trace,tokio=trace,runtime=trace".into() - }), - ) - .with(console_subscriber::ConsoleLayer::builder().spawn()) - .with(tracing_subscriber::fmt::layer()) - .init(); - // Handle command-line args let matches = command!() .arg( arg!(-b --bind "Bind to specific address. Default is 127.0.0.1:3030") .required(false), ) + .arg( + arg!(-v --verbose "Extra verbosity for use with tokio-console or to satisfy curiosity") + .required(false), + ) .get_matches(); let bind_addr; - if let Some(addr) = matches.get_one::("bind") { bind_addr = String::from(addr); } else { bind_addr = String::from("127.0.0.1:3030"); } + let trace_level; + if *matches.get_one::("verbose").unwrap() { + trace_level = "server=trace,tower_http=trace,lib=trace,tokio=trace,runtime=trace" + } else { + trace_level = "server=trace,tower_http=trace,lib=trace"; + } + + // Set up tracing + tracing_subscriber::registry() + .with( + tracing_subscriber::EnvFilter::try_from_default_env() + .unwrap_or_else(|_| trace_level.into()), + ) + .with(console_subscriber::ConsoleLayer::builder().spawn()) + .with(tracing_subscriber::fmt::layer()) + .init(); + // Set up rate limiting/governor let governor_conf = Arc::new( GovernorConfigBuilder::default() @@ -59,16 +67,16 @@ async fn main() -> Result<()> { .unwrap(), ); - let governor_limiter = governor_conf.limiter().clone(); let interval = Duration::from_secs(60); - // a separate background task to clean up + let governor_limiter = governor_conf.limiter().clone(); + std::thread::spawn(move || loop { std::thread::sleep(interval); tracing::info!("rate limiting storage size: {}", governor_limiter.len()); governor_limiter.retain_recent(); }); - // Set up state + // Set up globals let (tx_broadcast, _rx_broadcast) = broadcast::channel(32); let (tx_game_handler, mut rx_game_handler) = mpsc::channel(32); let (tx_incoming_message_handler, mut rx_incoming_message_handler) = mpsc::channel(32);