From bc2b7232d438a7ba444c3c048f7a534a9e9ee63e Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 9 Sep 2021 09:31:18 -0700 Subject: [PATCH] readme: simplify usage with init() (#124) --- README.md | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ed2939d8..c4129fea 100644 --- a/README.md +++ b/README.md @@ -86,24 +86,11 @@ others. ## using it to **instrument an application using Tokio**, add a dependency on the -[`console-subscriber`] crate, and **add the `TasksLayer` type** to your -[`tracing`] subscriber. for example: +[`console-subscriber`] crate, and **add this one-liner** to the top of your +`main` function: + ```rust - use tracing_subscriber::{prelude::*, fmt, EnvFilter}; - // construct the `console_subscriber` layer and the console wire protocol server - let (layer, server) = console_subscriber::TasksLayer::new(); - // ensure that Tokio's internal instrumentation is enabled - let filter = EnvFilter::from_default_env().add_directive("tokio=trace".parse()?); - - tracing_subscriber::registry() - // the `TasksLayer` can be used in combination with other `tracing` layers... - .with(tracing_subscriber::fmt::layer()) - .with(filter) - .with(layer) - .init(); - - // spawn the server task - tokio::spawn(server.serve()); +console_subscriber::init(); ``` notes: