Commit f2c30d5
authored
feat(subscriber): use per-layer filtering (#140)
Currently, the `console_subscriber::build()` and
`console_subscriber::init()` functions configure an `EnvFilter` that
enables the `tokio` and `runtime` targets, plus any targets configured
by `RUST_LOG`. This means that the `tokio` spans used by the console
will always be enabled at the `TRACE` level for all layers. This
includes the `fmt` layer we previously added in `init`.
Since this resulted in the `fmt` layer logs being cluttered with a bunch
of `tokio=trace` spans and events even when only high-level application
logs are enabled by `RUST_LOG`, we removed the `fmt` layer in PR #64.
However, tokio-rs/tracing#1523 was recently merged and [released][1],
adding support for [per-layer filtering][2] to `tracing-subscriber`. We
can now use the per-layer filtering API to selectively enable the
`tokio`/`runtime` spans and events at the `TRACE` level _only_ for the
`TasksLayer`, and add a filter to the `fmt` layer based on `RUST_LOG`.
This allows us to put back the `fmt` layer in
`console_subscriber::init`.
Now, if we run the example app (which uses `init`) with a `RUST_LOG`
value that enables only the app's logs, we get nice output:

However, we can also enable the `console-subscriber` crate's internal
logging:

And, we can still enable `tokio=trace` ourselves, if we actually _want_
to see all the task spans and waker events:

I also added some `trace!` and `debug!` macros in `examples/app.rs` to
demo that `console_subscriber::init()` also enables logging.
Closes #761 parent 738335f commit f2c30d5
File tree
4 files changed
+68
-19
lines changed- console-subscriber
- examples
- src
4 files changed
+68
-19
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| 80 | + | |
76 | 81 | | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
6 | | - | |
| 11 | + | |
7 | 12 | | |
8 | | - | |
| 13 | + | |
| 14 | + | |
9 | 15 | | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
16 | 28 | | |
17 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
18 | 33 | | |
19 | 34 | | |
20 | 35 | | |
| |||
28 | 43 | | |
29 | 44 | | |
30 | 45 | | |
31 | | - | |
| 46 | + | |
32 | 47 | | |
33 | 48 | | |
34 | 49 | | |
| |||
42 | 57 | | |
43 | 58 | | |
44 | 59 | | |
| 60 | + | |
| 61 | + | |
45 | 62 | | |
46 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
47 | 76 | | |
48 | 77 | | |
49 | 78 | | |
50 | 79 | | |
51 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
52 | 84 | | |
53 | 85 | | |
54 | 86 | | |
55 | 87 | | |
56 | | - | |
| 88 | + | |
57 | 89 | | |
| 90 | + | |
58 | 91 | | |
59 | 92 | | |
60 | 93 | | |
61 | 94 | | |
62 | | - | |
| 95 | + | |
63 | 96 | | |
64 | 97 | | |
65 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
66 | 105 | | |
67 | | - | |
| 106 | + | |
68 | 107 | | |
69 | 108 | | |
70 | 109 | | |
| |||
76 | 115 | | |
77 | 116 | | |
78 | 117 | | |
79 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
80 | 123 | | |
81 | 124 | | |
82 | 125 | | |
83 | 126 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
87 | 130 | | |
88 | | - | |
| 131 | + | |
89 | 132 | | |
90 | 133 | | |
91 | 134 | | |
| |||
0 commit comments