Expand description
This crate allows tools to enable rust logging without having to magically match rustc’s tracing crate version.
For example if someone is working on rustc_ast and wants to write some
minimal code against it to run in a debugger, with access to the debug!
logs emitted by rustc_ast, that can be done by writing:
[dependencies]
rustc_ast = { path = "../rust/compiler/rustc_ast" }
rustc_log = { path = "../rust/compiler/rustc_log" }
fn main() {
rustc_log::init_logger(rustc_log::LoggerConfig::from_env("LOG")).unwrap();
/* ... */
}
Now LOG=debug cargo +nightly run
will run your minimal main.rs and show
rustc’s debug logging. In a workflow like this, one might also add
std::env::set_var("LOG", "debug")
to the top of main so that cargo +nightly run
by itself is sufficient to get logs.
The reason rustc_log is a tiny separate crate, as opposed to exposing the same things in rustc_driver only, is to enable the above workflow. If you had to depend on rustc_driver in order to turn on rustc’s debug logs, that’s an enormously bigger dependency tree; every change you make to rustc_ast (or whichever piece of the compiler you are interested in) would involve rebuilding all the rest of rustc up to rustc_driver in order to run your main.rs. Whereas by depending only on rustc_log and the few crates you are debugging, you can make changes inside those crates and quickly run main.rs to read the debug logs.
Structs§
- Backtrace
Formatter 🔒 - Logger
Config - The values of all the environment variables that matter for configuring a logger. Errors are explicitly preserved so that we can share error handling.
Enums§
Traits§
- Build
Subscriber Ret - Trait alias for the complex return type of
build_subscriber
in init_logger_with_additional_layer. A Registry with any composition of tracing::Subscribers (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 ontracing_subscriber
.
Functions§
- init_
logger - Initialize the logger with the given values for the filter, coloring, and other options env variables.
- init_
logger_ with_ additional_ layer - 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)
. - stderr_
isatty - stdout_
isatty