Skip to content

Commit

Permalink
Add env-logger
Browse files Browse the repository at this point in the history
Add env-logger and configure with log level filter debug if the logger
is not configured via the RUST_LOG env variable.
  • Loading branch information
flxo committed Apr 27, 2022
1 parent 7e1cdad commit 95bcab9
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mqtt-v5-broker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ mqtt-v5 = { path = "../mqtt-v5", version = "0.2" }
nanoid = "0.3"
tokio = { version = "1", features = ["net", "rt-multi-thread", "sync", "time", "macros"] }
tokio-util = { version = "0.6", features = ["codec"] }
env_logger = "0.8.4"
8 changes: 8 additions & 0 deletions mqtt-v5-broker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use crate::{
broker::{Broker, BrokerMessage},
client::UnconnectedClient,
Expand Down Expand Up @@ -197,6 +199,12 @@ async fn websocket_server_loop(broker_tx: Sender<BrokerMessage>) {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
if env::var("RUST_LOG").is_err() {
env_logger::builder().filter(None, log::LevelFilter::Debug).init();
} else {
env_logger::init();
}

// Creating a Runtime does the following:
// * Spawn a background thread running a Reactor instance.
// * Start a ThreadPool for executing futures.
Expand Down

0 comments on commit 95bcab9

Please sign in to comment.