From 885cdfd61c399ec369714b510c901920490883a2 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Tue, 30 Aug 2022 13:49:23 -0700 Subject: [PATCH] Always log launch message. Users experience confusion when the server appears to do "nothing" when compiled in release mode. In reality, the server has started, but it offers no indication in that direction via log message. Often users misconfigure the port or address, but that information isn't displayed. This commit makes it such that only the final "Rocket has launched!" log message is displayed, which includes the listening address, port, and protocol. --- core/lib/src/config/config.rs | 50 ++++++++++++++++---------------- core/lib/src/fairing/fairings.rs | 4 +-- core/lib/src/log.rs | 12 +++++--- core/lib/src/rocket.rs | 4 +-- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/core/lib/src/config/config.rs b/core/lib/src/config/config.rs index 806cbf2a..b7a03df0 100644 --- a/core/lib/src/config/config.rs +++ b/core/lib/src/config/config.rs @@ -357,52 +357,52 @@ impl Config { Paint::default(val).bold() } - launch_info!("{}Configured for {}.", Paint::emoji("🔧 "), self.profile); - launch_info_!("address: {}", bold(&self.address)); - launch_info_!("port: {}", bold(&self.port)); - launch_info_!("workers: {}", bold(self.workers)); - launch_info_!("max blocking threads: {}", bold(self.max_blocking)); - launch_info_!("ident: {}", bold(&self.ident)); - launch_info_!("limits: {}", bold(&self.limits)); - launch_info_!("temp dir: {}", bold(&self.temp_dir.relative().display())); - launch_info_!("http/2: {}", bold(cfg!(feature = "http2"))); + launch_meta!("{}Configured for {}.", Paint::emoji("🔧 "), self.profile); + launch_meta_!("address: {}", bold(&self.address)); + launch_meta_!("port: {}", bold(&self.port)); + launch_meta_!("workers: {}", bold(self.workers)); + launch_meta_!("max blocking threads: {}", bold(self.max_blocking)); + launch_meta_!("ident: {}", bold(&self.ident)); + launch_meta_!("limits: {}", bold(&self.limits)); + launch_meta_!("temp dir: {}", bold(&self.temp_dir.relative().display())); + launch_meta_!("http/2: {}", bold(cfg!(feature = "http2"))); match self.keep_alive { - 0 => launch_info_!("keep-alive: {}", bold("disabled")), - ka => launch_info_!("keep-alive: {}{}", bold(ka), bold("s")), + 0 => launch_meta_!("keep-alive: {}", bold("disabled")), + ka => launch_meta_!("keep-alive: {}{}", bold(ka), bold("s")), } match (self.tls_enabled(), self.mtls_enabled()) { - (true, true) => launch_info_!("tls: {}", bold("enabled w/mtls")), - (true, false) => launch_info_!("tls: {} w/o mtls", bold("enabled")), - (false, _) => launch_info_!("tls: {}", bold("disabled")), + (true, true) => launch_meta_!("tls: {}", bold("enabled w/mtls")), + (true, false) => launch_meta_!("tls: {} w/o mtls", bold("enabled")), + (false, _) => launch_meta_!("tls: {}", bold("disabled")), } #[cfg(feature = "secrets")] { - launch_info_!("secret key: {}", bold(&self.secret_key)); + launch_meta_!("secret key: {}", bold(&self.secret_key)); if !self.secret_key.is_provided() { warn!("secrets enabled without a stable `secret_key`"); - launch_info_!("disable `secrets` feature or configure a `secret_key`"); - launch_info_!("this becomes an {} in non-debug profiles", Paint::red("error")); + launch_meta_!("disable `secrets` feature or configure a `secret_key`"); + launch_meta_!("this becomes an {} in non-debug profiles", Paint::red("error")); } } - launch_info_!("shutdown: {}", bold(&self.shutdown)); - launch_info_!("log level: {}", bold(self.log_level)); - launch_info_!("cli colors: {}", bold(&self.cli_colors)); + launch_meta_!("shutdown: {}", bold(&self.shutdown)); + launch_meta_!("log level: {}", bold(self.log_level)); + launch_meta_!("cli colors: {}", bold(&self.cli_colors)); // Check for now depreacted config values. for (key, replacement) in Self::DEPRECATED_KEYS { if let Some(md) = figment.find_metadata(key) { warn!("found value for deprecated config key `{}`", Paint::white(key)); if let Some(ref source) = md.source { - launch_info_!("in {} {}", Paint::white(source), md.name); + launch_meta_!("in {} {}", Paint::white(source), md.name); } if let Some(new_key) = replacement { - launch_info_!("key has been by replaced by `{}`", Paint::white(new_key)); + launch_meta_!("key has been by replaced by `{}`", Paint::white(new_key)); } else { - launch_info_!("key has no special meaning"); + launch_meta_!("key has no special meaning"); } } } @@ -413,9 +413,9 @@ impl Config { warn!("found set deprecated profile `{}`", Paint::white(profile)); if let Some(new_profile) = replacement { - launch_info_!("profile was replaced by `{}`", Paint::white(new_profile)); + launch_meta_!("profile was replaced by `{}`", Paint::white(new_profile)); } else { - launch_info_!("profile `{}` has no special meaning", profile); + launch_meta_!("profile `{}` has no special meaning", profile); } } } diff --git a/core/lib/src/fairing/fairings.rs b/core/lib/src/fairing/fairings.rs index 84685b27..dbc78b70 100644 --- a/core/lib/src/fairing/fairings.rs +++ b/core/lib/src/fairing/fairings.rs @@ -173,10 +173,10 @@ impl Fairings { pub fn pretty_print(&self) { let active_fairings = self.active().collect::>(); if !active_fairings.is_empty() { - launch_info!("{}{}:", Paint::emoji("📡 "), Paint::magenta("Fairings")); + launch_meta!("{}{}:", Paint::emoji("📡 "), Paint::magenta("Fairings")); for (_, fairing) in iter!(self, active_fairings.into_iter()) { - launch_info_!("{} ({})", Paint::default(fairing.info().name).bold(), + launch_meta_!("{} ({})", Paint::default(fairing.info().name).bold(), Paint::blue(fairing.info().kind).bold()); } } diff --git a/core/lib/src/log.rs b/core/lib/src/log.rs index 8e518ee0..ee346859 100644 --- a/core/lib/src/log.rs +++ b/core/lib/src/log.rs @@ -19,12 +19,16 @@ macro_rules! define_log_macro { ($d ($t:tt)*) => ($crate::log::private::$kind!(target: $target, $d ($t)*)) } ); + ($name:ident ($indented:ident): $kind:ident, $target:expr, $d:tt) => ( + define_log_macro!($name: $kind, $target, $d); + define_log_macro!($indented: $kind, $target, $d); + ); ($kind:ident, $indented:ident) => ( define_log_macro!($kind: $kind, module_path!(), $); define_log_macro!($indented: $kind, "_", $); pub use $indented; - ) + ); } define_log_macro!(error, error_); @@ -32,8 +36,8 @@ define_log_macro!(warn, warn_); define_log_macro!(info, info_); define_log_macro!(debug, debug_); define_log_macro!(trace, trace_); -define_log_macro!(launch_info: info, "rocket::launch", $); -define_log_macro!(launch_info_: info, "rocket::launch_", $); +define_log_macro!(launch_meta (launch_meta_): info, "rocket::launch", $); +define_log_macro!(launch_info (launch_msg_): warn, "rocket::launch", $); // `print!` panics when stdout isn't available, but this macro doesn't. See // SergioBenitez/Rocket#2019 and rust-lang/rust#46016 for more. @@ -80,7 +84,7 @@ pub trait PaintExt { fn emoji(item: &str) -> Paint<&str>; } -// Whether a record is a special `launch_info!` record. +// Whether a record is a special `launch_{meta,info}!` record. fn is_launch_record(record: &log::Metadata<'_>) -> bool { record.target().contains("rocket::launch") } diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs index e9188125..03e2021b 100644 --- a/core/lib/src/rocket.rs +++ b/core/lib/src/rocket.rs @@ -571,14 +571,14 @@ fn log_items(e: &str, t: &str, items: I, base: B, origin: O) { let mut items: Vec<_> = items.collect(); if !items.is_empty() { - launch_info!("{}{}:", Paint::emoji(e), Paint::magenta(t)); + launch_meta!("{}{}:", Paint::emoji(e), Paint::magenta(t)); } items.sort_by_key(|i| origin(i).path().as_str().chars().count()); items.sort_by_key(|i| origin(i).path().segments().len()); items.sort_by_key(|i| base(i).path().as_str().chars().count()); items.sort_by_key(|i| base(i).path().segments().len()); - items.iter().for_each(|i| launch_info_!("{}", i)); + items.iter().for_each(|i| launch_meta_!("{}", i)); } impl Rocket {