diff --git a/Cargo.lock b/Cargo.lock index b223cd57f..d952b7b98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,9 +22,11 @@ dependencies = [ "fdlimit 0.1.0", "hyper 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "json-ipc-server 0.2.4 (git+https://github.com/ethcore/json-ipc-server.git)", + "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -862,7 +864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "parity-dapps" version = "0.3.0" -source = "git+https://github.com/ethcore/parity-ui.git#4c5a972e81379cbf96fe6119a127d3540de14b1b" +source = "git+https://github.com/ethcore/parity-ui.git#f16a7e8b7f1ea4fe4da12af22f36a745a07513d6" dependencies = [ "aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -876,7 +878,7 @@ dependencies = [ [[package]] name = "parity-dapps-home" version = "0.5.2" -source = "git+https://github.com/ethcore/parity-ui.git#4c5a972e81379cbf96fe6119a127d3540de14b1b" +source = "git+https://github.com/ethcore/parity-ui.git#f16a7e8b7f1ea4fe4da12af22f36a745a07513d6" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-ui.git)", ] @@ -884,7 +886,7 @@ dependencies = [ [[package]] name = "parity-dapps-signer" version = "0.2.0" -source = "git+https://github.com/ethcore/parity-ui.git#4c5a972e81379cbf96fe6119a127d3540de14b1b" +source = "git+https://github.com/ethcore/parity-ui.git#f16a7e8b7f1ea4fe4da12af22f36a745a07513d6" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-ui.git)", ] @@ -892,7 +894,7 @@ dependencies = [ [[package]] name = "parity-dapps-status" version = "0.5.1" -source = "git+https://github.com/ethcore/parity-ui.git#4c5a972e81379cbf96fe6119a127d3540de14b1b" +source = "git+https://github.com/ethcore/parity-ui.git#f16a7e8b7f1ea4fe4da12af22f36a745a07513d6" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-ui.git)", ] @@ -900,7 +902,7 @@ dependencies = [ [[package]] name = "parity-dapps-wallet" version = "0.6.1" -source = "git+https://github.com/ethcore/parity-ui.git#4c5a972e81379cbf96fe6119a127d3540de14b1b" +source = "git+https://github.com/ethcore/parity-ui.git#f16a7e8b7f1ea4fe4da12af22f36a745a07513d6" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-ui.git)", ] diff --git a/Cargo.toml b/Cargo.toml index 281ea6243..77ea5e9c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,25 +17,27 @@ env_logger = "0.3" rustc-serialize = "0.3" docopt = "0.6" time = "0.1" -ctrlc = { git = "https://github.com/ethcore/rust-ctrlc.git" } -fdlimit = { path = "util/fdlimit" } num_cpus = "0.2" number_prefix = "0.2" rpassword = "0.2.1" -clippy = { version = "0.0.79", optional = true} +semver = "0.2" +ansi_term = "0.7" +lazy_static = "0.2" +regex = "0.1" +ctrlc = { git = "https://github.com/ethcore/rust-ctrlc.git" } +fdlimit = { path = "util/fdlimit" } ethcore = { path = "ethcore" } ethcore-util = { path = "util" } ethsync = { path = "sync" } ethcore-devtools = { path = "devtools" } ethcore-rpc = { path = "rpc" } ethcore-signer = { path = "signer" } -semver = "0.2" ethcore-ipc-nano = { path = "ipc/nano" } ethcore-ipc = { path = "ipc/rpc" } ethcore-ipc-hypervisor = { path = "ipc/hypervisor" } json-ipc-server = { git = "https://github.com/ethcore/json-ipc-server.git" } -ansi_term = "0.7" ethcore-dapps = { path = "dapps", optional = true } +clippy = { version = "0.0.79", optional = true} [target.'cfg(windows)'.dependencies] winapi = "0.2" diff --git a/parity/cli.rs b/parity/cli.rs index 07bba06d1..4fb2d2e51 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -264,6 +264,8 @@ Legacy Options: Miscellaneous Options: -l --logging LOGGING Specify the logging level. Must conform to the same format as RUST_LOG. + --log-file FILENAME Specify a filename into which logging should be + directed. --no-color Don't use terminal color codes in output. -v --version Show information about version. -h --help Show this screen. @@ -339,7 +341,7 @@ pub struct Args { pub flag_author: Option, pub flag_usd_per_tx: String, pub flag_usd_per_eth: String, - pub flag_price_update_period: String, + pub flag_price_update_period: String, pub flag_gas_floor_target: String, pub flag_gas_cap: String, pub flag_extra_data: Option, @@ -351,6 +353,7 @@ pub struct Args { pub flag_to: String, pub flag_format: Option, pub flag_jitvm: bool, + pub flag_log_file: Option, pub flag_no_color: bool, pub flag_no_network: bool, // legacy... diff --git a/parity/main.rs b/parity/main.rs index f1f018cc2..7314b9f99 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -50,6 +50,9 @@ extern crate ethcore_rpc; extern crate ethcore_signer; extern crate ansi_term; +#[macro_use] +extern crate lazy_static; +extern crate regex; #[cfg(feature = "dapps")] extern crate ethcore_dapps; @@ -184,7 +187,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) let panic_handler = PanicHandler::new_in_arc(); // Setup logging - let logger = setup_log::setup_log(&conf.args.flag_logging, conf.have_color()); + let logger = setup_log::setup_log(&conf.args.flag_logging, conf.have_color(), &conf.args.flag_log_file); // Raise fdlimit unsafe { ::fdlimit::raise_fd_limit(); } @@ -342,7 +345,7 @@ fn execute_export(conf: Configuration) { let panic_handler = PanicHandler::new_in_arc(); // Setup logging - let _logger = setup_log::setup_log(&conf.args.flag_logging, conf.have_color()); + let _logger = setup_log::setup_log(&conf.args.flag_logging, conf.have_color(), &conf.args.flag_log_file); // Raise fdlimit unsafe { ::fdlimit::raise_fd_limit(); } @@ -403,7 +406,7 @@ fn execute_import(conf: Configuration) { let panic_handler = PanicHandler::new_in_arc(); // Setup logging - let _logger = setup_log::setup_log(&conf.args.flag_logging, conf.have_color()); + let _logger = setup_log::setup_log(&conf.args.flag_logging, conf.have_color(), &conf.args.flag_log_file); // Raise fdlimit unsafe { ::fdlimit::raise_fd_limit(); } diff --git a/parity/setup_log.rs b/parity/setup_log.rs index d347a6bf0..fb45bd549 100644 --- a/parity/setup_log.rs +++ b/parity/setup_log.rs @@ -17,12 +17,16 @@ use std::env; use std::sync::Arc; +use std::fs::File; +use std::io::Write; use time; use env_logger::LogBuilder; +use regex::Regex; use util::RotatingLogger; +use util::log::{Applyable, Colour}; /// Sets up the logger -pub fn setup_log(init: &Option, enable_color: bool) -> Arc { +pub fn setup_log(init: &Option, enable_color: bool, log_to_file: &Option) -> Arc { use rlog::*; let mut levels = String::new(); @@ -45,14 +49,24 @@ pub fn setup_log(init: &Option, enable_color: bool) -> Arc, enable_color: bool) -> Arc String { + lazy_static! { + static ref RE: Regex = Regex::new("\x1b\\[[^m]+m").unwrap(); + } + RE.replace_all(s, "") +} + +#[test] +fn should_remove_colour() { + let before = "test"; + let after = kill_color(&before.apply(Colour::Red.bold())); + assert_eq!(after, "test"); +} + +#[test] +fn should_remove_multiple_colour() { + let t = format!("{} {}", Colour::Red.bold().paint("test"), Colour::White.normal().paint("again")); + let after = kill_color(&t); + assert_eq!(after, "test again"); +}