mirror of https://github.com/rwf2/Rocket.git
Print config info in all environments.
This commit is contained in:
parent
9403006ba4
commit
2d7b4b4233
|
@ -11,7 +11,7 @@ struct RocketLogger(LoggingLevel);
|
||||||
/// Defines the different levels for log messages.
|
/// Defines the different levels for log messages.
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||||
pub enum LoggingLevel {
|
pub enum LoggingLevel {
|
||||||
/// Only shows errors and warning.
|
/// Only shows errors, warnings, and launch information.
|
||||||
Critical,
|
Critical,
|
||||||
/// Shows everything except debug and trace information.
|
/// Shows everything except debug and trace information.
|
||||||
Normal,
|
Normal,
|
||||||
|
@ -58,20 +58,11 @@ impl fmt::Display for LoggingLevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)] #[macro_export]
|
#[doc(hidden)] #[macro_export]
|
||||||
macro_rules! log_ {
|
macro_rules! log_ { ($name:ident: $($args:tt)*) => { $name!(target: "_", $($args)*) }; }
|
||||||
($name:ident: $format:expr) => { log_!($name: $format,) };
|
|
||||||
($name:ident: $format:expr, $($args:expr),*) => {
|
|
||||||
$name!(target: "_", $format, $($args),*);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)] #[macro_export]
|
#[doc(hidden)] #[macro_export]
|
||||||
macro_rules! launch_info {
|
macro_rules! launch_info { ($($args:tt)*) => { error!(target: "launch", $($args)*) } }
|
||||||
($format:expr, $($args:expr),*) => {
|
#[doc(hidden)] #[macro_export]
|
||||||
error!(target: "launch", $format, $($args),*)
|
macro_rules! launch_info_ { ($($args:tt)*) => { error!(target: "launch_", $($args)*) } }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)] #[macro_export]
|
#[doc(hidden)] #[macro_export]
|
||||||
macro_rules! error_ { ($($args:expr),+) => { log_!(error: $($args),+); }; }
|
macro_rules! error_ { ($($args:expr),+) => { log_!(error: $($args),+); }; }
|
||||||
#[doc(hidden)] #[macro_export]
|
#[doc(hidden)] #[macro_export]
|
||||||
|
@ -98,20 +89,20 @@ impl Log for RocketLogger {
|
||||||
// We use the `launch_info` macro to "fake" a high priority info
|
// We use the `launch_info` macro to "fake" a high priority info
|
||||||
// message. We want to print the message unless the user uses a custom
|
// message. We want to print the message unless the user uses a custom
|
||||||
// drain, so we set it's status to critical, but reset it here to info.
|
// drain, so we set it's status to critical, but reset it here to info.
|
||||||
let level = match record.target() {
|
let (configged_level, level) = match record.target() {
|
||||||
"launch" => Info,
|
"launch" | "launch_" => (LoggingLevel::Normal, LogLevel::Info),
|
||||||
_ => record.level()
|
_ => (self.0, record.level())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Don't print Hyper or Rustls messages unless debug is enabled.
|
// Don't print Hyper or Rustls messages unless debug is enabled.
|
||||||
let from_hyper = record.location().module_path().starts_with("hyper::");
|
let from_hyper = record.location().module_path().starts_with("hyper::");
|
||||||
let from_rustls = record.location().module_path().starts_with("rustls::");
|
let from_rustls = record.location().module_path().starts_with("rustls::");
|
||||||
if self.0 != LoggingLevel::Debug && (from_hyper || from_rustls) {
|
if configged_level != LoggingLevel::Debug && (from_hyper || from_rustls) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In Rocket, we abuse target with value "_" to indicate indentation.
|
// In Rocket, we abuse targets with value "_" to indicate indentation.
|
||||||
if record.target() == "_" && self.0 != LoggingLevel::Critical {
|
if record.target().ends_with('_') && configged_level != LoggingLevel::Critical {
|
||||||
print!(" {} ", Paint::white("=>"));
|
print!(" {} ", Paint::white("=>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -375,22 +375,22 @@ impl Rocket {
|
||||||
logger::try_init(config.log_level, false);
|
logger::try_init(config.log_level, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{}Configured for {}.", Paint::masked("🔧 "), config.environment);
|
launch_info!("{}Configured for {}.", Paint::masked("🔧 "), config.environment);
|
||||||
info_!("address: {}", Paint::white(&config.address));
|
launch_info_!("address: {}", Paint::white(&config.address));
|
||||||
info_!("port: {}", Paint::white(&config.port));
|
launch_info_!("port: {}", Paint::white(&config.port));
|
||||||
info_!("log: {}", Paint::white(config.log_level));
|
launch_info_!("log: {}", Paint::white(config.log_level));
|
||||||
info_!("workers: {}", Paint::white(config.workers));
|
launch_info_!("workers: {}", Paint::white(config.workers));
|
||||||
info_!("secret key: {}", Paint::white(&config.secret_key));
|
launch_info_!("secret key: {}", Paint::white(&config.secret_key));
|
||||||
info_!("limits: {}", Paint::white(&config.limits));
|
launch_info_!("limits: {}", Paint::white(&config.limits));
|
||||||
|
|
||||||
let tls_configured = config.tls.is_some();
|
let tls_configured = config.tls.is_some();
|
||||||
if tls_configured && cfg!(feature = "tls") {
|
if tls_configured && cfg!(feature = "tls") {
|
||||||
info_!("tls: {}", Paint::white("enabled"));
|
launch_info_!("tls: {}", Paint::white("enabled"));
|
||||||
} else if tls_configured {
|
} else if tls_configured {
|
||||||
error_!("tls: {}", Paint::white("disabled"));
|
error_!("tls: {}", Paint::white("disabled"));
|
||||||
error_!("tls is configured, but the tls feature is disabled");
|
error_!("tls is configured, but the tls feature is disabled");
|
||||||
} else {
|
} else {
|
||||||
info_!("tls: {}", Paint::white("disabled"));
|
launch_info_!("tls: {}", Paint::white("disabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.secret_key.is_generated() && config.environment.is_prod() {
|
if config.secret_key.is_generated() && config.environment.is_prod() {
|
||||||
|
@ -398,10 +398,10 @@ impl Rocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, value) in config.extras() {
|
for (name, value) in config.extras() {
|
||||||
info_!("{} {}: {}",
|
launch_info_!("{} {}: {}",
|
||||||
Paint::yellow("[extra]"),
|
Paint::yellow("[extra]"),
|
||||||
Paint::blue(name),
|
Paint::blue(name),
|
||||||
Paint::white(LoggedValue(value)));
|
Paint::white(LoggedValue(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rocket {
|
Rocket {
|
||||||
|
|
Loading…
Reference in New Issue