Skip to content

Commit 3f14fae

Browse files
committed
feat: allow using specific formatters for tracing
1 parent 7fc5975 commit 3f14fae

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ Valid events are `new`, `enter`, `exit`, `close`, `active`, and `full`.
145145
See the [`tracing_subscriber` docs][tracing-events-docs-rs] for details
146146
on what the events mean.
147147

148+
It is also possible to use different tracing formatters using the
149+
`RUST_TRACING_FORMAT` variable. Supported values are: `full` (default),
150+
`compact`, and `pretty`.
151+
148152
#### MSRV Policy
149153
This crate adheres to Cargo's [semantic versioning rules][cargo-semver].
150154
At a minimum, it builds with the most recent Rust stable release minus

macros/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,26 @@ fn expand_tracing_init(attribute_args: &AttributeArgs) -> Tokens {
271271
}
272272
};
273273

274-
let _ = ::test_log::tracing_subscriber::FmtSubscriber::builder()
274+
let builder = ::test_log::tracing_subscriber::FmtSubscriber::builder()
275275
.with_env_filter(#env_filter)
276276
.with_span_events(__internal_event_filter)
277-
.with_test_writer()
278-
.try_init();
277+
.with_test_writer();
278+
279+
let _ = match ::std::env::var_os("RUST_TRACING_FORMAT").as_deref().and_then(std::ffi::OsStr::to_str) {
280+
None | Some("full") => {
281+
builder.try_init()
282+
}
283+
Some("compact") => {
284+
builder.compact().try_init()
285+
},
286+
#[cfg(feature = "color")]
287+
Some("pretty") => {
288+
builder.pretty().try_init()
289+
},
290+
Some(other) => {
291+
panic!("test-log: RUST_TRACING_FORMAT has an unsupported value of '{other}'. Supported are: full, compact, pretty.");
292+
}
293+
};
279294
}
280295
}
281296
}

0 commit comments

Comments
 (0)