From 2b6c48c91c85b7df045befa2749ca0352b16b9e5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 24 Dec 2020 01:24:25 +0000 Subject: [PATCH] logging Signed-off-by: Ian Jackson --- Cargo.lock.example | 24 ++++++++++++++++++++++++ wdriver.rs | 15 +++++++++++++-- wdriver/Cargo.toml | 2 ++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Cargo.lock.example b/Cargo.lock.example index 6b157bb6..7f1d6593 100644 --- a/Cargo.lock.example +++ b/Cargo.lock.example @@ -485,6 +485,19 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "env_logger" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54532e3223c5af90a6a757c90b5c5521564b07e5e7a958681bcd2afad421cdcd" +dependencies = [ + "atty", + "humantime", + "log 0.4.11", + "regex", + "termcolor", +] + [[package]] name = "erased-serde" version = "0.3.12" @@ -1562,9 +1575,11 @@ name = "otter-webdriver-tests" version = "0.0.1" dependencies = [ "anyhow", + "env_logger", "fehler", "humantime", "libc", + "log 0.4.11", "nix 0.19.1", "otter", "structopt", @@ -2467,6 +2482,15 @@ dependencies = [ "url 1.7.2", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" diff --git a/wdriver.rs b/wdriver.rs index e1873205..0dc7b980 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -4,9 +4,11 @@ pub use anyhow::{anyhow, Context}; pub use fehler::{throw, throws}; +pub use log::{debug, error, info, trace, warn}; +pub use log::{log, log_enabled}; +pub use nix::unistd::LinkatFlags; pub use structopt::StructOpt; pub use thirtyfour_sync as t4; -use nix::unistd::LinkatFlags; pub use void::Void; pub use t4::WebDriverCommands; @@ -40,7 +42,7 @@ where Self: anyhow::Context { fn always_context(self, msg: &'static str) -> anyhow::Result { let x = self.context(msg); - if x.is_ok() { eprintln!("completed {}.", msg) }; + if x.is_ok() { info!("completed {}.", msg) }; x } fn just_warn(self, msg: &'static str) -> Option { @@ -444,6 +446,15 @@ impl Drop for FinalInfoCollection { #[throws(AE)] pub fn setup() -> Setup { + env_logger::Builder::new() + .format_timestamp_micros() + .format_level(true) + .filter_module("otter_webdriver_tests", log::LevelFilter::Debug) + .filter_level(log::LevelFilter::Info) + .parse_env("OTTER_WDT_LOG") + .init(); + debug!("starting"); + let current_exe : String = env::current_exe() .context("find current executable")? .to_str() diff --git a/wdriver/Cargo.toml b/wdriver/Cargo.toml index 4e448ab0..601f0140 100644 --- a/wdriver/Cargo.toml +++ b/wdriver/Cargo.toml @@ -14,8 +14,10 @@ edition = "2018" otter = { path = ".." } anyhow = "1" +env_logger = "0.8" fehler = "1" humantime = "2" +log = "0.4" libc = "0.2" nix = "0.19" structopt = "0.3" -- 2.30.2