Skip to content

Commit

Permalink
Merge pull request #791 from CanalTP/tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean SIMARD authored Jul 9, 2021
2 parents 1414024 + 310e4d8 commit 4802ed9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
9 changes: 3 additions & 6 deletions gtfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ keywords = ["gtfs", "ntfs", "transit"]
chrono = "0.4"
failure = "0.1"
log = "0.4"
slog = "2.5"
slog-async = "2.3"
slog-envlogger = "2.1"
slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
tracing = { version = "0.1", features = ["log", "release_max_level_info"] }
tracing-log = "0.1"
tracing-subscriber = "0.2"
transit_model = { path = "../" }
lazy_static = "1"

Expand Down
27 changes: 5 additions & 22 deletions gtfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

use chrono::{DateTime, FixedOffset};
use log::info;
use slog::{slog_o, Drain};
use slog_async::OverflowStrategy;
use std::path::PathBuf;
use structopt::StructOpt;
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};
use transit_model::{read_utils, transfers::generates_transfers, PrefixConfiguration, Result};

lazy_static::lazy_static! {
Expand Down Expand Up @@ -94,25 +93,6 @@ struct Opt {
waiting_time: u32,
}

fn init_logger() -> slog_scope::GlobalLoggerGuard {
let decorator = slog_term::TermDecorator::new().stdout().build();
let drain = slog_term::CompactFormat::new(decorator).build().fuse();
let mut builder = slog_envlogger::LogBuilder::new(drain).filter(None, slog::FilterLevel::Info);
if let Ok(s) = std::env::var("RUST_LOG") {
builder = builder.parse(&s);
}
let drain = slog_async::Async::new(builder.build())
.chan_size(256) // Double the default size
.overflow_strategy(OverflowStrategy::Block)
.build()
.fuse();
let logger = slog::Logger::root(drain, slog_o!());

let scope_guard = slog_scope::set_global_logger(logger);
slog_stdlog::init().unwrap();
scope_guard
}

fn run(opt: Opt) -> Result<()> {
info!("Launching gtfs2ntfs...");

Expand Down Expand Up @@ -156,7 +136,10 @@ fn run(opt: Opt) -> Result<()> {
}

fn main() {
let _log_guard = init_logger();
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(tracing_subscriber::filter::EnvFilter::from_default_env())
.init();
if let Err(err) = run(Opt::from_args()) {
for cause in err.iter_chain() {
eprintln!("{}", cause);
Expand Down

0 comments on commit 4802ed9

Please sign in to comment.