|
| 1 | +// Copyright 2017 Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Polkadot. |
| 3 | + |
| 4 | +// Polkadot is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Polkadot is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +extern crate env_logger; |
| 18 | + |
| 19 | +#[macro_use] |
| 20 | +extern crate clap; |
| 21 | +#[macro_use] |
| 22 | +extern crate log; |
| 23 | + |
| 24 | +pub fn main() { |
| 25 | + let yaml = load_yaml!("./cli.yml"); |
| 26 | + let matches = clap::App::from_yaml(yaml).get_matches(); |
| 27 | + |
| 28 | + let log_pattern = matches.value_of("log").unwrap_or(""); |
| 29 | + init_logger(log_pattern); |
| 30 | + |
| 31 | + if let Some(_) = matches.subcommand_matches("collator") { |
| 32 | + info!("Starting collator."); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + if let Some(_) = matches.subcommand_matches("validator") { |
| 37 | + info!("Starting validator."); |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + println!("No command given.\n"); |
| 42 | + let _ = clap::App::from_yaml(yaml).print_long_help(); |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +fn init_logger(pattern: &str) { |
| 47 | + let mut builder = env_logger::LogBuilder::new(); |
| 48 | + // Disable info logging by default for some modules: |
| 49 | + builder.filter(Some("hyper"), log::LogLevelFilter::Warn); |
| 50 | + // Enable info for others. |
| 51 | + builder.filter(None, log::LogLevelFilter::Info); |
| 52 | + |
| 53 | + if let Ok(lvl) = std::env::var("RUST_LOG") { |
| 54 | + builder.parse(&lvl); |
| 55 | + } |
| 56 | + |
| 57 | + builder.parse(pattern); |
| 58 | + |
| 59 | + |
| 60 | + builder.init().expect("Logger initialized only once."); |
| 61 | +} |
0 commit comments