@@ -150,67 +150,107 @@ Cool, now I have a backtrace for the error!
150150# # Getting logging output
151151[getting-logging-output]: # getting-logging-output
152152
153- These crates are used in compiler for logging:
153+ The compiler uses the [ ` tracing ` ] crate for logging.
154154
155- * [log]
156- * [env-logger]
155+ [` tracing` ]: https://docs.rs/tracing
157156
158- [log]: https://docs.rs/log/0.4.6/log/index.html
159- [env-logger]: https://docs.rs/env_logger
160-
161- The compiler has a lot of ` debug! ` calls, which print out logging information
157+ The compiler has a lot of [` debug! ` ] calls, which print out logging information
162158at many points. These are very useful to at least narrow down the location of
163159a bug if not to find it entirely, or just to orient yourself as to why the
164160compiler is doing a particular thing.
165161
166- To see the logs, you need to set the ` RUSTC_LOG` environment variable to
167- your log filter, e.g. to get the logs for a specific module, you can run the
168- compiler as ` RUSTC_LOG=module::path rustc my-file.rs` . All ` debug! ` output will
169- then appear in standard error.
162+ [` debug! ` ]: https://docs.rs/tracing/0.1/tracing/macro.debug.html
163+
164+ To see the logs, you need to set the ` RUSTC_LOG` environment variable to your
165+ log filter. Your log filter can be just ` debug` to get all ` debug! ` output and
166+ higher (e.g., it will also include ` info! ` ), or ` path::to::module` to get * all*
167+ output (which will include ` trace! ` ) from a particular module, or
168+ ` path::to::module=debug` to get ` debug! ` output and higher from a particular
169+ module.
170+
171+ For example, to get the ` debug! ` output and higher for a specific module, you
172+ can run the compiler with ` RUSTC_LOG=path::to::module=debug rustc my-file.rs` .
173+ All ` debug! ` output will then appear in standard error.
170174
171- If you are developing rustdoc, use ` RUSTDOC_LOG` instead.
175+ Note that you can use a partial path and the filter will still work. For
176+ example, if you want to see ` info! ` output from only
177+ ` rustdoc::passes::collect_intra_doc_links` , you could use
178+ ` RUSTDOC_LOG=rustdoc::passes::collect_intra_doc_links=info` * or* you could use
179+ ` RUSTDOC_LOG=rustdoc::passes::collect_intra=info` .
172180
173- See the [env-logger] doc for more info on the full syntax. (Note: unlike the
174- compiler, the env-logger crate and its examples use the ` RUST_LOG` env
175- variable.)
181+ If you are developing rustdoc, use ` RUSTDOC_LOG` instead. If you are developing
182+ Miri, use ` MIRI_LOG` instead. You get the idea :)
183+
184+ See the [` tracing` ] crate' s docs, and specifically the docs for [`debug!`] to
185+ see the full syntax you can use. See the [env-logger] doc for more info on the
186+ full syntax. (Note: unlike the compiler, the [`tracing`] crate and its examples
187+ use the `RUST_LOG` environment variable. rustc, rustdoc, and other tools set
188+ custom environment variables.)
176189
177190**Note that unless you use a very strict filter, the logger will emit a lot of
178191output, so use the most specific module(s) you can (comma-separated if
179192multiple)**. It' s typically a good idea to pipe standard error to a file and
180193look at the log output with a text editor.
181194
182- So to put it together.
195+ So, to put it together:
183196
184197` ` ` bash
185198# This puts the output of all debug calls in `rustc_middle/src/traits` into
186199# standard error, which might fill your console backscroll.
187- $ RUSTC_LOG=rustc_middle::traits rustc +stage1 my-file.rs
200+ $ RUSTC_LOG=rustc_middle::traits=debug rustc +stage1 my-file.rs
188201
189202# This puts the output of all debug calls in `rustc_middle/src/traits` in
190203# `traits-log`, so you can then see it with a text editor.
191- $ RUSTC_LOG=rustc_middle::traits rustc +stage1 my-file.rs 2>traits-log
204+ $ RUSTC_LOG=rustc_middle::traits=debug rustc +stage1 my-file.rs 2> traits-log
192205
193- # Not recommended. This will show the output of all `debug!` calls
206+ # Not recommended! This will show the output of all `debug!` calls
194207# in the Rust compiler, and there are a *lot* of them, so it will be
195208# hard to find anything.
196209$ RUSTC_LOG=debug rustc +stage1 my-file.rs 2> all-log
197210
198- # This will show the output of all `info!` calls in `rustc_trans `.
211+ # This will show the output of all `info!` calls in `rustc_codegen_ssa `.
199212#
200- # There' s an ` info! ` statement in ` trans_instance ` that outputs
201- # every function that is translated . This is useful to find out
213+ # There's an `info!` statement in `codegen_instance ` that outputs
214+ # every function that is codegen'd . This is useful to find out
202215# which function triggers an LLVM assertion, and this is an `info!`
203216# log rather than a `debug!` log so it will work on the official
204217# compilers.
205- $ RUSTC_LOG=rustc_trans =info rustc +stage1 my-file.rs
218+ $ RUSTC_LOG=rustc_codegen_ssa =info rustc +stage1 my-file.rs
206219
207- # This will show the output of all `info!` calls made by rustdoc or any rustc library it calls.
220+ # This will show the output of all `info!` calls made by rustdoc
221+ # or any rustc library it calls.
208222$ RUSTDOC_LOG=info rustdoc +stage1 my-file.rs
209223
210- # This will only show `debug!` calls made by rustdoc directly, not any `rustc*` crate.
211- $ RUSTDOC_LOG=rustdoc rustdoc +stage1 my-file.rs
224+ # This will only show `debug!` calls made by rustdoc directly,
225+ # not any `rustc*` crate.
226+ $ RUSTDOC_LOG=rustdoc=debug rustdoc +stage1 my-file.rs
212227` ` `
213228
229+ # ## Log colors
230+
231+ By default, rustc (and other tools, like rustdoc and Miri) will be smart about
232+ when to use ANSI colors in the log output. If they are outputting to a terminal,
233+ they will use colors, and if they are outputting to a file or being piped
234+ somewhere else, they will not. However, it' s hard to read log output in your
235+ terminal unless you have a very strict filter, so you may want to pipe the
236+ output to a pager like `less`. But then there won' t be any colors, which makes
237+ it hard to pick out what you' re looking for!
238+
239+ You can override whether to have colors in log output with the `RUSTC_LOG_COLOR`
240+ environment variable (or `RUSTDOC_LOG_COLOR` for rustdoc, or `MIRI_LOG_COLOR`
241+ for Miri, etc.). There are three options: `auto` (the default), `always`, and
242+ `never`. So, if you want to enable colors when piping to `less`, use something
243+ similar to this command:
244+
245+ ```bash
246+ # The `-R` switch tells less to print ANSI colors without escaping them.
247+ $ RUSTC_LOG=debug RUSTC_LOG_COLOR=always rustc +stage1 ... | less -R
248+ ```
249+
250+ Note that `MIRI_LOG_COLOR` will only color logs that come from Miri, not logs
251+ from rustc functions that Miri calls. Use `RUSTC_LOG_COLOR` to color logs from
252+ rustc.
253+
214254### How to keep or remove `debug!` and `trace!` calls from the resulting binary
215255
216256While calls to `error!`, `warn!` and `info!` are included in every build of the compiler,
0 commit comments