Skip to content

Commit 90162ea

Browse files
committed
rustc_log: expose tracing-tree "wraparound" in an env var
1 parent a09d91b commit 90162ea

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: compiler/rustc_log/src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct LoggerConfig {
5757
pub verbose_entry_exit: Result<String, VarError>,
5858
pub verbose_thread_ids: Result<String, VarError>,
5959
pub backtrace: Result<String, VarError>,
60+
pub wraptree: Result<String, VarError>,
6061
}
6162

6263
impl LoggerConfig {
@@ -67,6 +68,7 @@ impl LoggerConfig {
6768
verbose_entry_exit: env::var(format!("{env}_ENTRY_EXIT")),
6869
verbose_thread_ids: env::var(format!("{env}_THREAD_IDS")),
6970
backtrace: env::var(format!("{env}_BACKTRACE")),
71+
wraptree: env::var(format!("{env}_WRAPTREE")),
7072
}
7173
}
7274
}
@@ -99,7 +101,7 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
99101
Err(_) => false,
100102
};
101103

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

115+
match cfg.wraptree {
116+
Ok(v) => match v.parse::<usize>() {
117+
Ok(v) => {
118+
layer = layer.with_wraparound(v);
119+
}
120+
Err(_) => return Err(Error::InvalidWraptree(v)),
121+
},
122+
Err(_) => {} // no wraptree
123+
}
124+
113125
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
114126
match cfg.backtrace {
115127
Ok(str) => {
@@ -164,6 +176,7 @@ pub fn stderr_isatty() -> bool {
164176
pub enum Error {
165177
InvalidColorValue(String),
166178
NonUnicodeColorValue,
179+
InvalidWraptree(String),
167180
}
168181

169182
impl std::error::Error for Error {}
@@ -179,6 +192,10 @@ impl Display for Error {
179192
formatter,
180193
"non-Unicode log color value: expected one of always, never, or auto",
181194
),
195+
Error::InvalidWraptree(value) => write!(
196+
formatter,
197+
"invalid log WRAPTREE value '{value}': expected a non-negative integer",
198+
),
182199
}
183200
}
184201
}

0 commit comments

Comments
 (0)