Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_log: expose tracing-tree "wraparound" in an env var #121934

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion compiler/rustc_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct LoggerConfig {
pub verbose_entry_exit: Result<String, VarError>,
pub verbose_thread_ids: Result<String, VarError>,
pub backtrace: Result<String, VarError>,
pub wraptree: Result<String, VarError>,
}

impl LoggerConfig {
Expand All @@ -67,6 +68,7 @@ impl LoggerConfig {
verbose_entry_exit: env::var(format!("{env}_ENTRY_EXIT")),
verbose_thread_ids: env::var(format!("{env}_THREAD_IDS")),
backtrace: env::var(format!("{env}_BACKTRACE")),
wraptree: env::var(format!("{env}_WRAPTREE")),
}
}
}
Expand Down Expand Up @@ -99,7 +101,7 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
Err(_) => false,
};

let layer = tracing_tree::HierarchicalLayer::default()
let mut layer = tracing_tree::HierarchicalLayer::default()
.with_writer(io::stderr)
.with_indent_lines(true)
.with_ansi(color_logs)
Expand All @@ -110,6 +112,16 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
.with_thread_ids(verbose_thread_ids)
.with_thread_names(verbose_thread_ids);

match cfg.wraptree {
Ok(v) => match v.parse::<usize>() {
Ok(v) => {
layer = layer.with_wraparound(v);
}
Err(_) => return Err(Error::InvalidWraptree(v)),
},
Err(_) => {} // no wraptree
}

let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
match cfg.backtrace {
Ok(str) => {
Expand Down Expand Up @@ -164,6 +176,7 @@ pub fn stderr_isatty() -> bool {
pub enum Error {
InvalidColorValue(String),
NonUnicodeColorValue,
InvalidWraptree(String),
}

impl std::error::Error for Error {}
Expand All @@ -179,6 +192,10 @@ impl Display for Error {
formatter,
"non-Unicode log color value: expected one of always, never, or auto",
),
Error::InvalidWraptree(value) => write!(
formatter,
"invalid log WRAPTREE value '{value}': expected a non-negative integer",
),
}
}
}
Loading