@@ -159,145 +159,12 @@ stack backtrace:
159159Cool, now I have a backtrace for the error!
160160
161161# # Getting logging output
162- [getting-logging-output]: # getting-logging-output
163162
164163The compiler uses the [` tracing` ] crate for logging.
165164
166165[` tracing` ]: https://docs.rs/tracing
167166
168- The compiler has a lot of [` debug! ` ] calls, which print out logging information
169- at many points. These are very useful to at least narrow down the location of
170- a bug if not to find it entirely, or just to orient yourself as to why the
171- compiler is doing a particular thing.
172-
173- [` debug! ` ]: https://docs.rs/tracing/0.1/tracing/macro.debug.html
174-
175- To see the logs, you need to set the ` RUSTC_LOG` environment variable to your
176- log filter. Your log filter can be just ` debug` to get all ` debug! ` output and
177- higher (e.g., it will also include ` info! ` ), or ` path::to::module` to get * all*
178- output (which will include ` trace! ` ) from a particular module, or
179- ` path::to::module=debug` to get ` debug! ` output and higher from a particular
180- module.
181-
182- For example, to get the ` debug! ` output and higher for a specific module, you
183- can run the compiler with ` RUSTC_LOG=path::to::module=debug rustc my-file.rs` .
184- All ` debug! ` output will then appear in standard error.
185-
186- Note that you can use a partial path and the filter will still work. For
187- example, if you want to see ` info! ` output from only
188- ` rustdoc::passes::collect_intra_doc_links` , you could use
189- ` RUSTDOC_LOG=rustdoc::passes::collect_intra_doc_links=info` * or* you could use
190- ` RUSTDOC_LOG=rustdoc::passes::collect_intra=info` .
191-
192- If you are developing rustdoc, use ` RUSTDOC_LOG` instead. If you are developing
193- Miri, use ` MIRI_LOG` instead. You get the idea :)
194-
195- See the [` tracing` ] crate' s docs, and specifically the docs for [`debug!`] to
196- see the full syntax you can use. (Note: unlike the compiler, the [`tracing`]
197- crate and its examples use the `RUST_LOG` environment variable. rustc, rustdoc,
198- and other tools set custom environment variables.)
199-
200- **Note that unless you use a very strict filter, the logger will emit a lot of
201- output, so use the most specific module(s) you can (comma-separated if
202- multiple)**. It' s typically a good idea to pipe standard error to a file and
203- look at the log output with a text editor.
204-
205- So, to put it together:
206-
207- ` ` ` bash
208- # This puts the output of all debug calls in `rustc_middle/src/traits` into
209- # standard error, which might fill your console backscroll.
210- $ RUSTC_LOG=rustc_middle::traits=debug rustc +stage1 my-file.rs
211-
212- # This puts the output of all debug calls in `rustc_middle/src/traits` in
213- # `traits-log`, so you can then see it with a text editor.
214- $ RUSTC_LOG=rustc_middle::traits=debug rustc +stage1 my-file.rs 2> traits-log
215-
216- # Not recommended! This will show the output of all `debug!` calls
217- # in the Rust compiler, and there are a *lot* of them, so it will be
218- # hard to find anything.
219- $ RUSTC_LOG=debug rustc +stage1 my-file.rs 2> all-log
220-
221- # This will show the output of all `info!` calls in `rustc_codegen_ssa`.
222- #
223- # There's an `info!` statement in `codegen_instance` that outputs
224- # every function that is codegen'd. This is useful to find out
225- # which function triggers an LLVM assertion, and this is an `info!`
226- # log rather than a `debug!` log so it will work on the official
227- # compilers.
228- $ RUSTC_LOG=rustc_codegen_ssa=info rustc +stage1 my-file.rs
229-
230- # This will show the output of all `info!` calls made by rustdoc
231- # or any rustc library it calls.
232- $ RUSTDOC_LOG=info rustdoc +stage1 my-file.rs
233-
234- # This will only show `debug!` calls made by rustdoc directly,
235- # not any `rustc*` crate.
236- $ RUSTDOC_LOG=rustdoc=debug rustdoc +stage1 my-file.rs
237- ` ` `
238-
239- # ## Log colors
240-
241- By default, rustc (and other tools, like rustdoc and Miri) will be smart about
242- when to use ANSI colors in the log output. If they are outputting to a terminal,
243- they will use colors, and if they are outputting to a file or being piped
244- somewhere else, they will not. However, it' s hard to read log output in your
245- terminal unless you have a very strict filter, so you may want to pipe the
246- output to a pager like `less`. But then there won' t be any colors, which makes
247- it hard to pick out what you' re looking for!
248-
249- You can override whether to have colors in log output with the `RUSTC_LOG_COLOR`
250- environment variable (or `RUSTDOC_LOG_COLOR` for rustdoc, or `MIRI_LOG_COLOR`
251- for Miri, etc.). There are three options: `auto` (the default), `always`, and
252- `never`. So, if you want to enable colors when piping to `less`, use something
253- similar to this command:
254-
255- ```bash
256- # The `-R` switch tells less to print ANSI colors without escaping them.
257- $ RUSTC_LOG=debug RUSTC_LOG_COLOR=always rustc +stage1 ... | less -R
258- ```
259-
260- Note that `MIRI_LOG_COLOR` will only color logs that come from Miri, not logs
261- from rustc functions that Miri calls. Use `RUSTC_LOG_COLOR` to color logs from
262- rustc.
263-
264- ### How to keep or remove `debug!` and `trace!` calls from the resulting binary
265-
266- While calls to `error!`, `warn!` and `info!` are included in every build of the compiler,
267- calls to `debug!` and `trace!` are only included in the program if
268- `debug-logging=true` is turned on in config.toml (it is
269- turned off by default), so if you don' t see ` DEBUG` logs, especially
270- if you run the compiler with ` RUSTC_LOG=rustc rustc some.rs` and only see
271- ` INFO` logs, make sure that ` debug-logging=true` is turned on in your
272- config.toml.
273-
274- # ## Logging etiquette and conventions
275-
276- Because calls to ` debug! ` are removed by default, in most cases, don' t worry
277- about adding "unnecessary" calls to `debug!` and leaving them in code you
278- commit - they won' t slow down the performance of what we ship, and if they
279- helped you pinning down a bug, they will probably help someone else with a
280- different one.
281-
282- A loosely followed convention is to use ` debug! (" foo(...)" )` at the _start_ of
283- a function `foo` and ` debug! (" foo: ..." )` _within_ the function. Another
284- loosely followed convention is to use the ` {:? }` format specifier for debug
285- logs.
286-
287- One thing to be ** careful** of is ** expensive** operations in logs.
288-
289- If in the module ` rustc::foo` you have a statement
290-
291- ` ` ` Rust
292- debug! (" {:?}" , random_operation(tcx));
293- ` ` `
294-
295- Then if someone runs a debug ` rustc` with ` RUSTC_LOG=rustc::bar` , then
296- `random_operation ()` will run.
297-
298- This means that you should not put anything too expensive or likely to crash
299- there - that would annoy anyone who wants to use logging for their own module.
300- No-one will know it until someone tries to use logging to find * another* bug.
167+ For details see [the guide section on tracing](./tracing.md)
301168
302169# # Formatting Graphviz output (.dot files)
303170[formatting-graphviz-output]: # formatting-graphviz-output
0 commit comments