Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] default logs to INFO (was NONE) #796

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Kisio Digital <team.coretools@kisio.com>", "Guillaume Pinot <texitoi@texitoi.eu>"]
name = "transit_model"
version = "0.39.0"
version = "0.40.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/CanalTP/transit_model"
Expand Down
23 changes: 20 additions & 3 deletions gtfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ use chrono::{DateTime, FixedOffset};
use log::info;
use std::path::PathBuf;
use structopt::StructOpt;
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};
use tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
layer::SubscriberExt as _,
util::SubscriberInitExt as _,
};
use transit_model::{read_utils, transfers::generates_transfers, PrefixConfiguration, Result};

lazy_static::lazy_static! {
Expand Down Expand Up @@ -135,11 +139,24 @@ fn run(opt: Opt) -> Result<()> {
Ok(())
}

fn main() {
fn init_logger() {
let default_level = LevelFilter::INFO;
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(tracing_subscriber::filter::EnvFilter::from_default_env())
.with(EnvFilter::try_from_default_env().unwrap_or_else(|e| {
eprintln!(
"missing or invalid {}, falling back to level '{}' - {}",
EnvFilter::DEFAULT_ENV,
default_level,
e,
);
EnvFilter::new(default_level.to_string())
}))
.init();
}

fn main() {
init_logger();
if let Err(err) = run(Opt::from_args()) {
for cause in err.iter_chain() {
eprintln!("{}", cause);
Expand Down