Skip to content

Commit c527fd2

Browse files
committed
Further tweaks to README contents
Address @hawkw review comments. Opted for clearer wording in passages joining examples together rather than extra reordering for now.
1 parent f193344 commit c527fd2

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,12 @@ fn main() {
7272
}
7373
```
7474

75-
[`tracing-subscriber`]: https://docs.rs/tracing-subscriber/
76-
[fmt]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html
77-
[`init()`]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/fn.init.html
78-
79-
This subscriber will be used as the default in all threads for the remainder of the duration
80-
of the program, similar to how loggers work in the `log` crate.
75+
Using `init()` calls [`set_global_default()`] so this subscriber will be used
76+
as the default in all threads for the remainder of the duration of the
77+
program, similar to how loggers work in the `log` crate.
8178

82-
In addition, you can locally override the default subscriber. For example:
79+
For more control, a subscriber can be built in stages and not set globally,
80+
but instead used to locally override the default subscriber. For example:
8381

8482
```rust
8583
use tracing::{info, Level};
@@ -108,6 +106,11 @@ currently executing thread; other threads will not see the change from with_defa
108106
Once a subscriber has been set, instrumentation points may be added to the
109107
executable using the `tracing` crate's macros.
110108

109+
[`tracing-subscriber`]: https://docs.rs/tracing-subscriber/
110+
[fmt]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html
111+
[`init()`]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/fn.init.html
112+
[`set_global_default()`]: https://docs.rs/tracing/latest/tracing/subscriber/fn.set_global_default.html
113+
111114
### In Libraries
112115

113116
Libraries should only rely on the `tracing` crate and use the provided macros
@@ -178,12 +181,12 @@ tracing = "0.1"
178181
```
179182

180183
Note: Libraries should *NOT* install a subscriber by using a method than calls
181-
`set_global_default()`, as this will cause conflicts when executables try to
184+
[`set_global_default()`], as this will cause conflicts when executables try to
182185
set the default later.
183186

184187
### In Asynchronous Code
185188

186-
To trace asynchronous code, the preferred method is using the [`#[instrument]`] attribute:
189+
To trace `async fn`s, the preferred method is using the [`#[instrument]`] attribute:
187190

188191
```rust
189192
use tracing::{info, instrument};
@@ -198,10 +201,12 @@ async fn write(stream: &mut TcpStream) -> io::Result<usize> {
198201
}
199202
```
200203

201-
This requires the [`tracing-futures`] crate to be specified as a dependency.
204+
The [`tracing-futures`] crate must be specified as a dependency to enable
205+
`async` support.
202206

203-
Code that makes use of [`std::future::Future`][std-future] or `async`/`await` needs
204-
special handling, as the following example _will not_ work:
207+
Special handling is needed for the general case of code using
208+
[`std::future::Future`][std-future] or blocks with `async`/`await`, as the
209+
following example _will not_ work:
205210

206211
```rust
207212
async {
@@ -240,7 +245,7 @@ attachment that `Future::instrument` does.
240245
[`tracing-futures`]: https://docs.rs/tracing-futures
241246
[closing]: https://docs.rs/tracing/latest/span/index.html#closing-spans
242247
[`Future::instrument`]: https://docs.rs/tracing-futures/latest/tracing_futures/trait.Instrument.html#method.instrument
243-
[`#[instrument]`]: https://docs.rs/tracing/0.1.11/tracing/attr.instrument.html
248+
[`#[instrument]`]: https://docs.rs/tracing/latest/tracing/attr.instrument.html
244249

245250

246251
## Getting Help

0 commit comments

Comments
 (0)