Skip to content

Commit

Permalink
Simplify tracing_subscriber initialization in the examples (#1524)
Browse files Browse the repository at this point in the history
The default features of `tracing_subscriber` already initialize `tracing` with
`tracing_log` and the env filter when `tracing_subscriber::fmt::init()` is used.
  • Loading branch information
nickelc committed Oct 2, 2021
1 parent bade6e5 commit 46f7608
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
8 changes: 2 additions & 6 deletions examples/e06_sample_bot_structure/src/main.rs
Expand Up @@ -22,7 +22,6 @@ use serenity::{
prelude::*,
};
use tracing::{error, info};
use tracing_subscriber::{EnvFilter, FmtSubscriber};

pub struct ShardManagerContainer;

Expand Down Expand Up @@ -56,11 +55,8 @@ async fn main() {
// Initialize the logger to use environment variables.
//
// In this case, a good default is setting the environment variable
// `RUST_LOG` to debug`.
let subscriber =
FmtSubscriber::builder().with_env_filter(EnvFilter::from_default_env()).finish();

tracing::subscriber::set_global_default(subscriber).expect("Failed to start the logger");
// `RUST_LOG` to `debug`.
tracing_subscriber::fmt::init();

let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");

Expand Down
1 change: 0 additions & 1 deletion examples/e15_simple_dashboard/Cargo.toml
Expand Up @@ -10,7 +10,6 @@ rillrate = "0.39"

tracing = "0.1"
tracing-subscriber = "0.2"
tracing-log = "0.1"

webbrowser = "0.5"

Expand Down
14 changes: 5 additions & 9 deletions examples/e15_simple_dashboard/src/main.rs
Expand Up @@ -335,15 +335,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
"info,e15_simple_dashboard=trace,meio=warn,rate_core=warn,rill_engine=warn",
);

// Increase compatibility with tracing and the log crate macros used by RillRate.
// Some weird things get logged without this if you use tracing.
tracing_log::LogTracer::init()?;
// Since we use tracing_log, we need to use a different way of subscribing to tracing events
// than shown in example 7.
let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.finish();
tracing::subscriber::set_global_default(subscriber)?;
// Initialize the logger to use environment variables.
//
// In this case, a good default is setting the environment variable
// `RUST_LOG` to `debug`, but for production, use the variable defined above.
tracing_subscriber::fmt::init();

// Start a server on `http://0.0.0.0:6361/`
// Currently the port is not configurable, but it will be soon enough; thankfully it's not a
Expand Down

0 comments on commit 46f7608

Please sign in to comment.