mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00

* subscriber: add less-verbose configuration APIs Signed-off-by: Eliza Weisman <eliza@buoyant.io> * even nicer easymode Signed-off-by: Eliza Weisman <eliza@buoyant.io> * wip## Motivation Users have said fairly frequently that configuring new subscribers in an application is unnecessarily verbose and confusing. We should try to make this nicer, especially as it's a common "on ramp" for new `tracing` users. ## Solution This branch adds new APIs, inspired by `tonic` and `warp`, that should make setting up a subscriber a little less verbose. This includes: - Many modules in `tracing-subscriber` now expose free functions that construct default instances of various types. This makes configuring subscribers using these types more concise, a la `warp`. - An extension trait for adding `.set_default`, `.init`, and `.try_init` methods to subscribers. This generalizes the similar functions on `fmt`'s `SubscriberBuilder` to work with other subscribers. All the old APIs are still left as they were previously. The new APIs just provide shorthand for them. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
37 lines
874 B
Rust
37 lines
874 B
Rust
mod support;
|
|
use self::support::*;
|
|
use tracing_subscriber::prelude::*;
|
|
|
|
#[test]
|
|
fn init_ext_works() {
|
|
let (subscriber, finished) = subscriber::mock()
|
|
.event(
|
|
event::mock()
|
|
.at_level(tracing::Level::INFO)
|
|
.with_target("init_works"),
|
|
)
|
|
.done()
|
|
.run_with_handle();
|
|
|
|
let _guard = subscriber.set_default();
|
|
tracing::info!(target: "init_works", "it worked!");
|
|
finished.assert_finished();
|
|
}
|
|
|
|
#[test]
|
|
fn builders_are_init_ext() {
|
|
tracing_subscriber::fmt().set_default();
|
|
let _ = tracing_subscriber::fmt()
|
|
.with_target(false)
|
|
.compact()
|
|
.try_init();
|
|
}
|
|
|
|
#[test]
|
|
fn layered_is_init_ext() {
|
|
tracing_subscriber::registry()
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.with(tracing_subscriber::EnvFilter::new("foo=info"))
|
|
.set_default();
|
|
}
|