Skip to content

Commit fd095fb

Browse files
committed
Document how RUST_LOG works
1 parent b510a74 commit fd095fb

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

doc/rust.texi

+41-20
Original file line numberDiff line numberDiff line change
@@ -3626,30 +3626,51 @@ communication facilities.
36263626

36273627
The runtime contains a system for directing logging expressions to a logging
36283628
console and/or internal logging buffers. @xref{Ref.Expr.Log}. Logging
3629-
expressions can be enabled or disabled via a two-dimensional filtering process:
3629+
expressions can be enabled per module.
3630+
3631+
Logging output is enabled by setting the @code{RUST_LOG} environment variable.
3632+
@code{RUST_LOG} accepts a logging specification that is a comma-separated list
3633+
of paths. For each module containing log statements, if @code{RUST_LOG}
3634+
contains the path to that module or a parent of that module, then its logs
3635+
will be output to the console. The path to an module consists of the crate
3636+
name, any parent modules, then the module itself, all separated by double
3637+
colons (@code{::}).
3638+
3639+
As an example, to see all the logs generated by the compiler, you would set
3640+
@code{RUST_LOG} to @code{rustc}, which is the crate name (as specified in its
3641+
@code{link} attribute). @xref{Ref.Comp.Crate}. To narrow down the logs to
3642+
just crate resolution, you would set it to @code{rustc::metadata::creader}.
3643+
3644+
Note that when compiling either .rs or .rc files that don't specifiy a crate
3645+
name the crate is given a default name that matches the source file, sans
3646+
extension. In that case, to turn on logging for a program compiled from, e.g.
3647+
helloworld.rs, @code{RUST_LOG} should be set to @code{helloworld}.
3648+
3649+
As a convenience, the logging spec can also be set to a special psuedo-crate,
3650+
@code{::help}. In this case, when the application starts, the runtime will
3651+
simply output a list of loaded modules containing log statements, then exit.
3652+
3653+
The Rust runtime itself generates logging information. The runtime's logs are
3654+
generated for a number of artificial modules in the @code{::rt} psuedo-crate,
3655+
and can be enabled just like the logs for any standard module. The full list
3656+
of runtime logging modules follows.
36303657

36313658
@itemize
3632-
3633-
@sp 1
3634-
@item
3635-
By Item
3636-
3637-
Each @emph{item} (module, function, iterator, object, type) in Rust has a
3638-
static path within its crate module, and can have logging enabled or
3639-
disabled on a path-prefix basis.
3640-
3641-
@sp 1
3642-
@item
3643-
By Task
3644-
3645-
Each @emph{task} in a running Rust program has a unique ownership relation
3646-
through the task ownership tree, and can have logging enabled or disabled on
3647-
an ownership-ancestry basis.
3659+
@item @code{::rt::mem} Memory management
3660+
@item @code{::rt::comm} Messaging and task communication
3661+
@item @code{::rt::task} Task management
3662+
@item @code{::rt::dom} Task scheduling
3663+
@item @code{::rt::trace} Unused
3664+
@item @code{::rt::cache} Type descriptor cache
3665+
@item @code{::rt::upcall} Compiler-generated runtime calls
3666+
@item @code{::rt::timer} The scheduler timer
3667+
@item @code{::rt::gc} Garbage collection
3668+
@item @code{::rt::stdlib} Functions used directly by the standard library
3669+
@item @code{::rt::kern} The runtime kernel
3670+
@item @code{::rt::backtrace} Unused
3671+
@item @code{::rt::callback} Unused
36483672
@end itemize
36493673

3650-
Logging is integrated into the language for efficiency reasons, as well as the
3651-
need to filter logs based on these two built-in dimensions.
3652-
36533674
@node Ref.Run.Sig
36543675
@subsection Ref.Run.Sig
36553676
@c * Ref.Run.Sig:: Runtime signal handler.

0 commit comments

Comments
 (0)