Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit abb434f228474b9f94ef5689f4e643090045c002
parent 76c830a467920f818ca1ff7d9e92798c2755f6f8
Author: Sergio Benitez <sb@sergio.bz>
Date:   Mon, 19 Nov 2018 02:11:38 -0800

Stop using white for legible logging everywhere.

Prior to this change, Rocket emitted "white" text in much of its logging
output. On terminals with light backgrounds, the text was nearly
illegible. This PR stops using white coloring altogether, opting instead
to use the terminal's default color albeit with bold styling. On dark
terminals, this will likely be a light color, and on light terminals,
this will likely be a dark color. The end result is that Rocket's
logging output should be readable everywhere.

Resolves #639.

Diffstat:
Mcontrib/codegen/Cargo.toml | 2+-
Mcontrib/codegen/build.rs | 15+++++++--------
Mcore/codegen/Cargo.toml | 2+-
Mcore/codegen/build.rs | 15+++++++--------
Mcore/lib/Cargo.toml | 4++--
Mcore/lib/build.rs | 15+++++++--------
Mcore/lib/src/config/error.rs | 48++++++++++++++++++++++++------------------------
Mcore/lib/src/error.rs | 2+-
Mcore/lib/src/fairing/fairings.rs | 4++--
Mcore/lib/src/logger.rs | 13+++++++------
Mcore/lib/src/outcome.rs | 2+-
Mcore/lib/src/rocket.rs | 50+++++++++++++++++++++++++-------------------------
Mcore/lib/src/router/route.rs | 10+++++-----
13 files changed, 90 insertions(+), 92 deletions(-)

diff --git a/contrib/codegen/Cargo.toml b/contrib/codegen/Cargo.toml @@ -22,5 +22,5 @@ devise = "0.1" quote = "0.6" [build-dependencies] -yansi = "0.4" +yansi = { git = "https://github.com/SergioBenitez/yansi", rev = "59c3a91" } version_check = "0.1.3" diff --git a/contrib/codegen/build.rs b/contrib/codegen/build.rs @@ -4,7 +4,7 @@ extern crate yansi; extern crate version_check; -use yansi::Color::{Red, Yellow, Blue, White}; +use yansi::Color::{Red, Yellow, Blue}; use version_check::{supports_features, is_min_version, is_min_date}; // Specifies the minimum nightly version needed to compile Rocket. @@ -19,9 +19,9 @@ fn main() { let print_version_err = |version: &str, date: &str| { eprintln!("{} {}. {} {}.", - White.paint("Installed version is:"), + "Installed version is:", Yellow.paint(format!("{} ({})", version, date)), - White.paint("Minimum required:"), + "Minimum required:", Yellow.paint(format!("{} ({})", MIN_VERSION, MIN_DATE))); }; @@ -29,11 +29,11 @@ fn main() { if !ok_channel { eprintln!("{} {}", Red.paint("Error:").bold(), - White.paint("Rocket requires a nightly or dev version of Rust.")); + "Rocket requires a nightly or dev version of Rust."); print_version_err(&*version, &*date); eprintln!("{}{}{}", Blue.paint("See the getting started guide ("), - White.paint("https://rocket.rs/v0.4/guide/getting-started/"), + "https://rocket.rs/v0.4/guide/getting-started/", Blue.paint(") for more information.")); panic!("Aborting compilation due to incompatible compiler.") } @@ -41,10 +41,9 @@ fn main() { if !ok_version || !ok_date { eprintln!("{} {}", Red.paint("Error:").bold(), - White.paint("Rocket requires a more recent version of rustc.")); + "Rocket requires a more recent version of rustc."); eprintln!("{}{}{}", - Blue.paint("Use `"), - White.paint("rustup update"), + Blue.paint("Use `"), "rustup update", Blue.paint("` or your preferred method to update Rust.")); print_version_err(&*version, &*date); panic!("Aborting compilation due to incompatible compiler.") diff --git a/core/codegen/Cargo.toml b/core/codegen/Cargo.toml @@ -21,7 +21,7 @@ rocket_http = { version = "0.4.0-rc.1", path = "../http/" } devise = "0.1" [build-dependencies] -yansi = "0.4" +yansi = { git = "https://github.com/SergioBenitez/yansi", rev = "59c3a91" } version_check = "0.1.3" [dev-dependencies] diff --git a/core/codegen/build.rs b/core/codegen/build.rs @@ -4,7 +4,7 @@ extern crate yansi; extern crate version_check; -use yansi::Color::{Red, Yellow, Blue, White}; +use yansi::Color::{Red, Yellow, Blue}; use version_check::{supports_features, is_min_version, is_min_date}; // Specifies the minimum nightly version needed to compile Rocket. @@ -19,9 +19,9 @@ fn main() { let print_version_err = |version: &str, date: &str| { eprintln!("{} {}. {} {}.", - White.paint("Installed version is:"), + "Installed version is:", Yellow.paint(format!("{} ({})", version, date)), - White.paint("Minimum required:"), + "Minimum required:", Yellow.paint(format!("{} ({})", MIN_VERSION, MIN_DATE))); }; @@ -29,11 +29,11 @@ fn main() { if !ok_channel { eprintln!("{} {}", Red.paint("Error:").bold(), - White.paint("Rocket requires a nightly or dev version of Rust.")); + "Rocket requires a nightly or dev version of Rust."); print_version_err(&*version, &*date); eprintln!("{}{}{}", Blue.paint("See the getting started guide ("), - White.paint("https://rocket.rs/v0.4/guide/getting-started/"), + "https://rocket.rs/v0.4/guide/getting-started/", Blue.paint(") for more information.")); panic!("Aborting compilation due to incompatible compiler.") } @@ -41,10 +41,9 @@ fn main() { if !ok_version || !ok_date { eprintln!("{} {}", Red.paint("Error:").bold(), - White.paint("Rocket requires a more recent version of rustc.")); + "Rocket requires a more recent version of rustc."); eprintln!("{}{}{}", - Blue.paint("Use `"), - White.paint("rustup update"), + Blue.paint("Use `"), "rustup update", Blue.paint("` or your preferred method to update Rust.")); print_version_err(&*version, &*date); panic!("Aborting compilation due to incompatible compiler.") diff --git a/core/lib/Cargo.toml b/core/lib/Cargo.toml @@ -22,7 +22,7 @@ private-cookies = ["rocket_http/private-cookies"] [dependencies] rocket_codegen = { version = "0.4.0-rc.1", path = "../codegen" } rocket_http = { version = "0.4.0-rc.1", path = "../http" } -yansi = "0.4" +yansi = { git = "https://github.com/SergioBenitez/yansi", rev = "59c3a91" } log = "0.4" toml = "0.4.7" num_cpus = "1.0" @@ -38,7 +38,7 @@ isatty = "0.1" lazy_static = "1.0" [build-dependencies] -yansi = "0.4" +yansi = { git = "https://github.com/SergioBenitez/yansi", rev = "59c3a91" } version_check = "0.1.3" [package.metadata.docs.rs] diff --git a/core/lib/build.rs b/core/lib/build.rs @@ -4,7 +4,7 @@ extern crate yansi; extern crate version_check; -use yansi::Color::{Red, Yellow, Blue, White}; +use yansi::Color::{Red, Yellow, Blue}; use version_check::{supports_features, is_min_version, is_min_date}; // Specifies the minimum nightly version needed to compile Rocket. @@ -19,9 +19,9 @@ fn main() { let print_version_err = |version: &str, date: &str| { eprintln!("{} {}. {} {}.", - White.paint("Installed version is:"), + "Installed version is:", Yellow.paint(format!("{} ({})", version, date)), - White.paint("Minimum required:"), + "Minimum required:", Yellow.paint(format!("{} ({})", MIN_VERSION, MIN_DATE))); }; @@ -29,11 +29,11 @@ fn main() { if !ok_channel { eprintln!("{} {}", Red.paint("Error:").bold(), - White.paint("Rocket requires a nightly or dev version of Rust.")); + "Rocket requires a nightly or dev version of Rust."); print_version_err(&*version, &*date); eprintln!("{}{}{}", Blue.paint("See the getting started guide ("), - White.paint("https://rocket.rs/v0.4/guide/getting-started/"), + "https://rocket.rs/v0.4/guide/getting-started/", Blue.paint(") for more information.")); panic!("Aborting compilation due to incompatible compiler.") } @@ -41,10 +41,9 @@ fn main() { if !ok_version || !ok_date { eprintln!("{} {}", Red.paint("Error:").bold(), - White.paint("Rocket requires a more recent version of rustc.")); + "Rocket requires a more recent version of rustc."); eprintln!("{}{}{}", - Blue.paint("Use `"), - White.paint("rustup update"), + Blue.paint("Use `"), "rustup update", Blue.paint("` or your preferred method to update Rust.")); print_version_err(&*version, &*date); panic!("Aborting compilation due to incompatible compiler.") diff --git a/core/lib/src/config/error.rs b/core/lib/src/config/error.rs @@ -1,12 +1,12 @@ +use std::{io, fmt}; use std::path::PathBuf; use std::error::Error; -use std::{io, fmt}; + +use yansi::Paint; use super::Environment; use self::ConfigError::*; -use yansi::Color::White; - /// The type of a configuration error. #[derive(Debug)] pub enum ConfigError { @@ -60,53 +60,53 @@ impl ConfigError { NotFound => error!("config file was not found"), IoError => error!("failed reading the config file: IO error"), Io(ref error, param) => { - error!("I/O error while setting {}:", White.paint(param)); + error!("I/O error while setting {}:", Paint::default(param).bold()); info_!("{}", error); } BadFilePath(ref path, reason) => { - error!("configuration file path '{:?}' is invalid", path); + error!("configuration file path {} is invalid", Paint::default(path.display()).bold()); info_!("{}", reason); } BadEntry(ref name, ref filename) => { - let valid_entries = format!("{}, and global", valid_envs); - error!("[{}] is not a known configuration environment", name); - info_!("in {:?}", White.paint(filename)); - info_!("valid environments are: {}", White.paint(valid_entries)); + let valid_entries = format!("{}, global", valid_envs); + error!("{} is not a known configuration environment", + Paint::default(format!("[{}]", name)).bold()); + info_!("in {}", Paint::default(filename.display()).bold()); + info_!("valid environments are: {}", Paint::default(valid_entries).bold()); } BadEnv(ref name) => { - error!("'{}' is not a valid ROCKET_ENV value", name); - info_!("valid environments are: {}", White.paint(valid_envs)); + error!("{} is not a valid ROCKET_ENV value", Paint::default(name).bold()); + info_!("valid environments are: {}", Paint::default(valid_envs).bold()); } BadType(ref name, expected, actual, ref filename) => { - error!("{} key could not be parsed", White.paint(name)); + error!("{} key could not be parsed", Paint::default(name).bold()); if let Some(filename) = filename { - info_!("in {:?}", White.paint(filename)); + info_!("in {}", Paint::default(filename.display()).bold()); } info_!("expected value to be {}, but found {}", - White.paint(expected), White.paint(actual)); + Paint::default(expected).bold(), Paint::default(actual).bold()); } ParseError(_, ref filename, ref desc, line_col) => { error!("config file failed to parse due to invalid TOML"); info_!("{}", desc); + info_!("in {}", Paint::default(filename.display()).bold()); if let Some((line, col)) = line_col { - info_!("at {:?}:{}:{}", White.paint(filename), - White.paint(line + 1), White.paint(col + 1)); - } else { - info_!("in {:?}", White.paint(filename)); + info_!("at line {}, column {}", + Paint::default(line + 1).bold(), Paint::default(col + 1).bold()); } } BadEnvVal(ref key, ref value, ref error) => { - error!("environment variable '{}={}' could not be parsed", - White.paint(key), White.paint(value)); - info_!("{}", White.paint(error)); + error!("environment variable {} could not be parsed", + Paint::default(format!("ROCKET_{}={}", key.to_uppercase(), value)).bold()); + info_!("{}", error); } UnknownKey(ref key) => { - error!("the configuration key '{}' is unknown and disallowed in \ - this position", White.paint(key)); + error!("the configuration key {} is unknown and disallowed in \ + this position", Paint::default(key).bold()); } Missing(ref key) => { - error!("missing configuration key: '{}'", White.paint(key)); + error!("missing configuration key: {}", Paint::default(key).bold()); } } } diff --git a/core/lib/src/error.rs b/core/lib/src/error.rs @@ -207,7 +207,7 @@ impl Drop for LaunchError { LaunchErrorKind::FailedFairings(ref failures) => { error!("Rocket failed to launch due to failing fairings:"); for fairing in failures { - info_!("{}", Paint::white(fairing)); + info_!("{}", fairing); } panic!("launch fairing failure"); diff --git a/core/lib/src/fairing/fairings.rs b/core/lib/src/fairing/fairings.rs @@ -87,13 +87,13 @@ impl Fairings { .collect::<Vec<_>>() .join(", "); - info_!("{} {}: {}", Paint::white(num), kind, Paint::white(names)); + info_!("{} {}: {}", Paint::default(num).bold(), kind, Paint::default(names).bold()); } } pub fn pretty_print_counts(&self) { if !self.all_fairings.is_empty() { - info!("{}{}:", Paint::masked("📡 "), Paint::purple("Fairings")); + info!("{}{}:", Paint::masked("📡 "), Paint::magenta("Fairings")); self.info_for("launch", &self.launch); self.info_for("request", &self.request); self.info_for("response", &self.response); diff --git a/core/lib/src/logger.rs b/core/lib/src/logger.rs @@ -105,24 +105,25 @@ impl log::Log for RocketLogger { } // In Rocket, we abuse targets with suffix "_" to indicate indentation. + let is_launch = record.target().starts_with("launch"); if record.target().ends_with('_') { - if configged_level != LoggingLevel::Critical || record.target().starts_with("launch") { - print!(" {} ", Paint::white("=>")); + if configged_level != LoggingLevel::Critical || is_launch { + print!(" {} ", Paint::default("=>").bold()); } } match record.level() { - log::Level::Info => println!("{}", Paint::blue(record.args())), - log::Level::Trace => println!("{}", Paint::purple(record.args())), + log::Level::Info => println!("{}", Paint::blue(record.args()).wrap()), + log::Level::Trace => println!("{}", Paint::magenta(record.args()).wrap()), log::Level::Error => { println!("{} {}", Paint::red("Error:").bold(), - Paint::red(record.args())) + Paint::red(record.args()).wrap()) } log::Level::Warn => { println!("{} {}", Paint::yellow("Warning:").bold(), - Paint::yellow(record.args())) + Paint::yellow(record.args()).wrap()) } log::Level::Debug => { print!("\n{} ", Paint::blue("-->").bold()); diff --git a/core/lib/src/outcome.rs b/core/lib/src/outcome.rs @@ -633,6 +633,6 @@ impl<S, E, F> fmt::Debug for Outcome<S, E, F> { impl<S, E, F> fmt::Display for Outcome<S, E, F> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (color, string) = self.formatting(); - write!(f, "{}", Paint::new(string).fg(color)) + write!(f, "{}", Paint::default(string).fg(color)) } } diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs @@ -247,7 +247,7 @@ impl Rocket { Outcome::Forward(data) => { // There was no matching route. Autohandle `HEAD` requests. if request.method() == Method::Head { - info_!("Autohandling {} request.", Paint::white("HEAD")); + info_!("Autohandling {} request.", Paint::default("HEAD").bold()); // Dispatch the request again with Method `GET`. request._set_method(Method::Get); @@ -290,7 +290,7 @@ impl Rocket { // Check if the request processing completed or if the request needs // to be forwarded. If it does, continue the loop to try again. - info_!("{} {}", Paint::white("Outcome:"), outcome); + info_!("{} {}", Paint::default("Outcome:").bold(), outcome); match outcome { o@Outcome::Success(_) | o@Outcome::Failure(_) => return o, Outcome::Forward(unused_data) => data = unused_data, @@ -391,27 +391,27 @@ impl Rocket { logger::push_max_level(logger::LoggingLevel::Normal); } - launch_info!("{}Configured for {}.", Paint::masked("🔧 "), config.environment); - launch_info_!("address: {}", Paint::white(&config.address)); - launch_info_!("port: {}", Paint::white(&config.port)); - launch_info_!("log: {}", Paint::white(config.log_level)); - launch_info_!("workers: {}", Paint::white(config.workers)); - launch_info_!("secret key: {}", Paint::white(&config.secret_key)); - launch_info_!("limits: {}", Paint::white(&config.limits)); + launch_info!("{}Configured for {}.", Paint::masked("🔧 "), config.environment); + launch_info_!("address: {}", Paint::default(&config.address).bold()); + launch_info_!("port: {}", Paint::default(&config.port).bold()); + launch_info_!("log: {}", Paint::default(config.log_level).bold()); + launch_info_!("workers: {}", Paint::default(config.workers).bold()); + launch_info_!("secret key: {}", Paint::default(&config.secret_key).bold()); + launch_info_!("limits: {}", Paint::default(&config.limits).bold()); match config.keep_alive { - Some(v) => launch_info_!("keep-alive: {}", Paint::white(format!("{}s", v))), - None => launch_info_!("keep-alive: {}", Paint::white("disabled")), + Some(v) => launch_info_!("keep-alive: {}", Paint::default(format!("{}s", v)).bold()), + None => launch_info_!("keep-alive: {}", Paint::default("disabled").bold()), } let tls_configured = config.tls.is_some(); if tls_configured && cfg!(feature = "tls") { - launch_info_!("tls: {}", Paint::white("enabled")); + launch_info_!("tls: {}", Paint::default("enabled").bold()); } else if tls_configured { - error_!("tls: {}", Paint::white("disabled")); + error_!("tls: {}", Paint::default("disabled").bold()); error_!("tls is configured, but the tls feature is disabled"); } else { - launch_info_!("tls: {}", Paint::white("disabled")); + launch_info_!("tls: {}", Paint::default("disabled").bold()); } if config.secret_key.is_generated() && config.environment.is_prod() { @@ -420,9 +420,8 @@ impl Rocket { for (name, value) in config.extras() { launch_info_!("{} {}: {}", - Paint::yellow("[extra]"), - Paint::blue(name), - Paint::white(LoggedValue(value))); + Paint::yellow("[extra]"), name, + Paint::default(LoggedValue(value)).bold()); } Rocket { @@ -491,10 +490,11 @@ impl Rocket { /// ``` #[inline] pub fn mount<R: Into<Vec<Route>>>(mut self, base: &str, routes: R) -> Self { - info!("{}{} '{}':", + info!("{}{} {}{}", Paint::masked("🛰 "), - Paint::purple("Mounting"), - Paint::blue(base)); + Paint::magenta("Mounting"), + Paint::blue(base), + Paint::magenta(":")); let base_uri = Origin::parse(base) .unwrap_or_else(|e| { @@ -550,7 +550,7 @@ impl Rocket { /// ``` #[inline] pub fn register(mut self, catchers: Vec<Catcher>) -> Self { - info!("{}{}:", Paint::masked("👾 "), Paint::purple("Catchers")); + info!("{}{}", Paint::masked("👾 "), Paint::magenta("Catchers:")); for c in catchers { if self.catchers.get(&c.code).map_or(false, |e| !e.is_default) { info_!("{} {}", c, Paint::yellow("(warning: duplicate catcher!)")); @@ -709,10 +709,10 @@ impl Rocket { let full_addr = format!("{}:{}", self.config.address, self.config.port); launch_info!("{}{} {}{}", - Paint::masked("🚀 "), - Paint::white("Rocket has launched from"), - Paint::white(proto).bold(), - Paint::white(&full_addr).bold()); + Paint::masked("🚀 "), + Paint::default("Rocket has launched from").bold(), + Paint::default(proto).bold().underline(), + Paint::default(&full_addr).bold().underline()); // Restore the log level back to what it originally was. logger::pop_max_level(); diff --git a/core/lib/src/router/route.rs b/core/lib/src/router/route.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Display}; use std::convert::From; -use yansi::Color::*; +use yansi::Paint; use codegen::StaticRouteInfo; use handler::Handler; @@ -282,19 +282,19 @@ impl Route { impl fmt::Display for Route { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} {}", Green.paint(&self.method), Blue.paint(&self.uri))?; + write!(f, "{} {}", Paint::green(&self.method), Paint::blue(&self.uri))?; if self.rank > 1 { - write!(f, " [{}]", White.paint(&self.rank))?; + write!(f, " [{}]", Paint::default(&self.rank).bold())?; } if let Some(ref format) = self.format { - write!(f, " {}", Yellow.paint(format))?; + write!(f, " {}", Paint::yellow(format))?; } if let Some(name) = self.name { write!(f, " {}{}{}", - Cyan.paint("("), Purple.paint(name), Cyan.paint(")"))?; + Paint::cyan("("), Paint::magenta(name), Paint::cyan(")"))?; } Ok(())