Use closure to allow passing custom tracing layers

The previous method, where a layer would be passed directly,
required to pass a "no-op" layer when no custom layer was needed.
This should have in theory worked, however having a no-op layer
seems to change the way the tracing lib applies filters internally,
leading to some debug!() being printed despite them being out of
the minimum level for the filters. Note however that this behavior
was very inconsistent, and e.g. some debug!() would get printed
and some others wouldn't, for no apparent reason.
This commit is contained in:
Stypox
2025-06-11 10:23:43 +02:00
parent 0d74252537
commit fc96ca8bba
2 changed files with 29 additions and 13 deletions

View File

@@ -1507,13 +1507,15 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
}
}
pub fn init_logger_with_additional_layer(
pub fn init_logger_with_additional_layer<F, T>(
early_dcx: &EarlyDiagCtxt,
cfg: rustc_log::LoggerConfig,
additional_tracing_layer: impl rustc_log::Layer<rustc_log::Registry> + Send + Sync,
) {
if let Err(error) = rustc_log::init_logger_with_additional_layer(cfg, additional_tracing_layer)
{
build_subscriber: F,
) where
F: FnOnce() -> T,
T: rustc_log::BuildSubscriberRet,
{
if let Err(error) = rustc_log::init_logger_with_additional_layer(cfg, build_subscriber) {
early_dcx.early_fatal(error.to_string());
}
}