docs/development-guide/tracing-logging.md
Rolldown's codebase has a lot of tracing::debug! (or tracing::trace!) calls, which print out logging information at many points. These are very useful to at least narrow down the location of a bug if not to find it entirely, or just to orient yourself as to why the compiler is doing a particular thing.
To see the logs, you need to set the RD_LOG environment variable to your log filter. The full syntax of the log filters can be found in the rustdoc of tracing-subscriber.
RD_LOG=debug [executing rolldown]
RD_LOG=debug RD_LOG_OUTPUT=chrome-json [executing rolldown]
It's fine to add tracing::debug! or tracing::trace! calls in your PRs. However, to avoid noise in the logs, you should be careful about choosing tracing::debug! or tracing::trace!.
There are some rules that help you to choose right logging level:
tracing::trace!.tracing::debug!.tracing::trace!.tracing::debug!.tracing::trace!.These rules also apply to the #[tracing::instrument] attribute.
#[tracing::instrument(level = "debug", skip_all)].#[tracing::instrument(level = "trace", skip_all].::: info What information should be traced could be opinionated, so the reviewer will decide whether to let you leave tracing statements in or whether to ask you to remove them before merging. :::
Lots of functions in rolldown are annotated with
#[instrument(level = "debug", skip(self))]
fn foo(&self, bar: Type) {}
#[instrument(level = "debug", skip_all)]
fn baz(&self, bar: Type) {}
which allows you to use
RUSTC_LOG=[foo]
to do the following all at once
fooskip list)Notices:
We generally recommend using skip_all unless you have a good reason to use logging for the arguments.
Rolldown uses oxc-resolver, which exposes trace information for debugging purposes.
RD_LOG='oxc_resolver' rolldown
This emits trace information for the oxc_resolver::resolve function, e.g.
2024-06-11T07:12:20.003537Z DEBUG oxc_resolver: options: ResolveOptions { ... }, path: "...", specifier: "...", ret: "..."
at /path/to/oxc_resolver-1.8.1/src/lib.rs:212
in oxc_resolver::resolve with path: "...", specifier: "..."
The input values are options, path and specifier, the returned value is ret.