Skip to content

Commit 1908c8e

Browse files
committed
Emit tracing output to stderr
Behavior of the crate differs between the log and tracing backends: while log defaults to printing messages to stderr, tracing emits them to stdout. Until version 0.3.19 the tracing-subscriber crate did not allow changing this default. Pull request #3187 [0] changed that and release 0.3.20 contains this logic. Now that we can, adjust the tracing based backend to log to stderr for consistency. [0] tokio-rs/tracing#3187
1 parent 7fc5975 commit 1908c8e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Unreleased
2+
----------
3+
- Adjusted `tracing` output to log to `stderr`
4+
5+
16
0.2.18
27
------
38
- Improved cooperation with other similar procedural macros to enable

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ unstable = ["test-log-macros/unstable"]
7878

7979
[dependencies]
8080
test-log-macros = {version = "0.2.18", path = "macros"}
81-
tracing-subscriber = {version = "0.3.17", default-features = false, optional = true, features = ["env-filter", "fmt"]}
81+
tracing-subscriber = {version = "0.3.20", default-features = false, optional = true, features = ["env-filter", "fmt"]}
8282
env_logger = {version = "0.11", default-features = false, optional = true}
8383

8484
[dev-dependencies]
@@ -88,5 +88,12 @@ test-case = "3.1"
8888
tokio = {version = "1.38", default-features = false, features = ["rt-multi-thread", "macros"]}
8989
tracing = "0.1"
9090

91+
# A set of unused dependencies that we require to force correct minimum
92+
# versions of transitive dependencies, for cases where our dependencies
93+
# have incorrect dependency specifications themselves.
94+
95+
# error: cannot find macro `__lazy_static_internal` in this scope
96+
_lazy_static_unused = { package = "lazy_static", version = "1.0.2" }
97+
9198
[lints]
9299
workspace = true

macros/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ fn expand_logging_init(attribute_args: &AttributeArgs) -> Tokens {
208208
::test_log::env_logger::Env::default()
209209
.default_filter_or(#default_filter)
210210
)
211+
.target(::test_log::env_logger::Target::Stderr)
211212
.is_test(true)
212213
.try_init();
213214
}
@@ -274,7 +275,7 @@ fn expand_tracing_init(attribute_args: &AttributeArgs) -> Tokens {
274275
let _ = ::test_log::tracing_subscriber::FmtSubscriber::builder()
275276
.with_env_filter(#env_filter)
276277
.with_span_events(__internal_event_filter)
277-
.with_test_writer()
278+
.with_writer(::test_log::tracing_subscriber::fmt::TestWriter::with_stderr)
278279
.try_init();
279280
}
280281
}

0 commit comments

Comments
 (0)