Always disable colors if requested or unavailable.

Resolves #1712.
This commit is contained in:
Sergio Benitez 2021-06-18 21:50:43 -07:00
parent abf996b026
commit a875da1666
1 changed files with 17 additions and 17 deletions

View File

@ -129,32 +129,32 @@ impl log::Log for RocketLogger {
} }
} }
pub(crate) fn init_default() -> bool { pub(crate) fn init_default() {
crate::log::init(&crate::Config::debug_default()) crate::log::init(&crate::Config::debug_default())
} }
pub(crate) fn init(config: &crate::Config) -> bool { pub(crate) fn init(config: &crate::Config) {
static HAS_ROCKET_LOGGER: AtomicBool = AtomicBool::new(false); static ROCKET_LOGGER_SET: AtomicBool = AtomicBool::new(false);
let r = log::set_boxed_logger(Box::new(RocketLogger)); // Try to initialize Rocket's logger, recording if we succeeded.
if r.is_ok() { if log::set_boxed_logger(Box::new(RocketLogger)).is_ok() {
HAS_ROCKET_LOGGER.store(true, Ordering::Release); ROCKET_LOGGER_SET.store(true, Ordering::Release);
} }
// If another has been set, don't touch anything. // Always disable colors if requested or if they won't work on Windows.
if !HAS_ROCKET_LOGGER.load(Ordering::Acquire) { if !config.cli_colors || !Paint::enable_windows_ascii() {
return false; Paint::disable();
} }
if !atty::is(atty::Stream::Stdout) // Set Rocket-logger specific settings only if Rocket's logger is set.
|| (cfg!(windows) && !Paint::enable_windows_ascii()) if ROCKET_LOGGER_SET.load(Ordering::Acquire) {
|| !config.cli_colors // Rocket logs to stdout, so disable coloring if it's not a TTY.
{ if !atty::is(atty::Stream::Stdout) {
Paint::disable(); Paint::disable();
} }
log::set_max_level(config.log_level.to_level_filter()); log::set_max_level(config.log_level.to_level_filter());
true }
} }
impl LogLevel { impl LogLevel {