Skip to content

Commit d79b224

Browse files
committed
Add information about logging macros to the tutorial.
Closes #5699.
1 parent 260d74d commit d79b224

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/rust.md

+22
Original file line numberDiff line numberDiff line change
@@ -3251,6 +3251,28 @@ of runtime logging modules follows.
32513251
* `::rt::backtrace` Log a backtrace on task failure
32523252
* `::rt::callback` Unused
32533253

3254+
#### Logging Expressions
3255+
3256+
Rust provides several macros to log information. Here's a simple Rust program
3257+
that demonstrates all four of them:
3258+
3259+
```rust
3260+
fn main() {
3261+
error!("This is an error log")
3262+
warn!("This is a warn log")
3263+
info!("this is an info log")
3264+
debug!("This is a dubug log")
3265+
}
3266+
```
3267+
3268+
These four log levels correspond to levels 1-4, as controlled by `RUST_LOG`:
3269+
3270+
```bash
3271+
$ RUST_LOG=rust=3 ./rust
3272+
rust: ~"\"This is na error log\""
3273+
rust: ~"\"This is a warn log\""
3274+
rust: ~"\"this is an info log\""
3275+
```
32543276

32553277
# Appendix: Rationales and design tradeoffs
32563278

0 commit comments

Comments
 (0)