diff options
| author | bors <bors@rust-lang.org> | 2025-06-14 04:58:22 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-14 04:58:22 +0000 | 
| commit | 64033a4ee541c3e9c178fd593e979c74bb798cdc (patch) | |
| tree | 0e0507dd657636c5ffe0e8cc9eb1ef48047e722b /compiler/rustc_log/src | |
| parent | 64c81fd10509924ca4da5d93d6052a65b75418a5 (diff) | |
| parent | 572b452bd50ae2c01ee783f584dbcd3fbd2e87f9 (diff) | |
| download | rust-64033a4ee541c3e9c178fd593e979c74bb798cdc.tar.gz rust-64033a4ee541c3e9c178fd593e979c74bb798cdc.zip | |
Auto merge of #142483 - workingjubilee:rollup-8qnhueh, r=workingjubilee
Rollup of 16 pull requests Successful merges: - rust-lang/rust#140969 (Allow initializing logger with additional tracing Layer) - rust-lang/rust#141352 (builtin dyn impl no guide inference) - rust-lang/rust#142046 (add Vec::peek_mut) - rust-lang/rust#142273 (tests: Minicore `extern "gpu-kernel"` feature test) - rust-lang/rust#142302 (Rework how the disallowed qualifier in function type diagnostics are generated) - rust-lang/rust#142405 (Don't hardcode the intrinsic return types twice in the compiler) - rust-lang/rust#142434 ( Pre-install JS dependencies in tidy Dockerfile) - rust-lang/rust#142439 (doc: mention that intrinsics should not be called in user code) - rust-lang/rust#142441 (Delay replacing escaping bound vars in `FindParamInClause`) - rust-lang/rust#142449 (Require generic params for const generic params) - rust-lang/rust#142452 (Remove "intermittent" wording from `ReadDir`) - rust-lang/rust#142459 (Remove output helper bootstrap) - rust-lang/rust#142460 (cleanup search graph impl) - rust-lang/rust#142461 (compiletest: Clarify that `--no-capture` is needed with `--verbose`) - rust-lang/rust#142475 (Add platform support docs & maintainers for *-windows-msvc) - rust-lang/rust#142480 (tests: Convert two handwritten minicores to add-core-stubs) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_log/src')
| -rw-r--r-- | compiler/rustc_log/src/lib.rs | 33 | 
1 files changed, 32 insertions, 1 deletions
| diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index 1bb502ca3d0..df648bbd489 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -43,6 +43,7 @@ use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter}; use tracing_subscriber::fmt::FmtContext; use tracing_subscriber::fmt::format::{self, FormatEvent, FormatFields}; use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::{Layer, Registry}; /// The values of all the environment variables that matter for configuring a logger. /// Errors are explicitly preserved so that we can share error handling. @@ -72,6 +73,36 @@ impl LoggerConfig { /// Initialize the logger with the given values for the filter, coloring, and other options env variables. pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> { + init_logger_with_additional_layer(cfg, || Registry::default()) +} + +/// Trait alias for the complex return type of `build_subscriber` in +/// [init_logger_with_additional_layer]. A [Registry] with any composition of [tracing::Subscriber]s +/// (e.g. `Registry::default().with(custom_layer)`) should be compatible with this type. +/// Having an alias is also useful so rustc_driver_impl does not need to explicitly depend on +/// `tracing_subscriber`. +pub trait BuildSubscriberRet: + tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span> + Send + Sync +{ +} + +impl< + T: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span> + Send + Sync, +> BuildSubscriberRet for T +{ +} + +/// Initialize the logger with the given values for the filter, coloring, and other options env variables. +/// Additionally add a custom layer to collect logging and tracing events via `build_subscriber`, +/// for example: `|| Registry::default().with(custom_layer)`. +pub fn init_logger_with_additional_layer<F, T>( + cfg: LoggerConfig, + build_subscriber: F, +) -> Result<(), Error> +where + F: FnOnce() -> T, + T: BuildSubscriberRet, +{ let filter = match cfg.filter { Ok(env) => EnvFilter::new(env), _ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)), @@ -124,7 +155,7 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> { Err(_) => {} // no wraptree } - let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer); + let subscriber = build_subscriber().with(layer.with_filter(filter)); match cfg.backtrace { Ok(backtrace_target) => { let fmt_layer = tracing_subscriber::fmt::layer() | 
