Skip to content

Commit

Permalink
Log dependency warnings/errors at trace level
Browse files Browse the repository at this point in the history
Fixes alacritty#5387.
  • Loading branch information
sbosnick authored Aug 4, 2021
1 parent fd0fe96 commit d5c66ce
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions alacritty/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};

use glutin::event_loop::EventLoopProxy;
use log::{self, Level};
use log::{self, Level, LevelFilter};

use crate::cli::Options;
use crate::event::Event;
Expand Down Expand Up @@ -102,8 +102,8 @@ impl log::Log for Logger {
let index = record.target().find(':').unwrap_or_else(|| record.target().len());
let target = &record.target()[..index];

// Only log our own crates.
if !self.enabled(record.metadata()) || !ALLOWED_TARGETS.contains(&target) {
// Only log our own crates, except when logging at Level::Trace.
if !self.enabled(record.metadata()) || !is_allowed_target(record.level(), target) {
return;
}

Expand Down Expand Up @@ -149,6 +149,14 @@ fn create_log_message(record: &log::Record<'_>, target: &str) -> String {
message
}

/// Check if log messages from a crate should be logged.
fn is_allowed_target(level: Level, target: &str) -> bool {
match (level, log::max_level()) {
(Level::Error, LevelFilter::Trace) | (Level::Warn, LevelFilter::Trace) => true,
_ => ALLOWED_TARGETS.contains(&target),
}
}

struct OnDemandLogFile {
file: Option<LineWriter<File>>,
created: Arc<AtomicBool>,
Expand Down

0 comments on commit d5c66ce

Please sign in to comment.