Bug 1399441 - Hide Firefox stdout/stderr if log level is info level or higher
This patch will quench stdout/stderr from Firefox by default, which
is believed to cause unneeded confusion amongst geckodriver users
leading them to file false bugs.
If the effective log level is config or lower (config/debug/trace)
the output will be inherited as it is is currently.
MozReview-Commit-ID: 9F2xwAyclrv
--- a/testing/geckodriver/CHANGES.md
+++ b/testing/geckodriver/CHANGES.md
@@ -9,16 +9,19 @@ Unreleased
### Changed
- HTTP status code for the [`StaleElementReference`] error changed
from 400 (Bad Request) to 404 (Not Found)
- Backtraces from geckodriver no longer substitute for missing
Marionette stacktraces
+- Output from Firefox is now quenched by default. It can be
+ resurfaced by increasing the logging verbosity to config level or below.
+
0.19.1 (2017-10-30)
-------------------
### Changed
- Search suggestions in the location bar turned off as not to
trigger network connections
--- a/testing/geckodriver/src/logging.rs
+++ b/testing/geckodriver/src/logging.rs
@@ -18,27 +18,28 @@ lazy_static! {
static ref ATOMIC_DRAIN: AtomicSwitchCtrl<io::Error> = AtomicSwitch::new(
slog::Discard.map_err(|_| io::Error::new(io::ErrorKind::Other, "should not happen"))
).ctrl();
static ref FIRST_RUN: AtomicBool = AtomicBool::new(true);
}
static DEFAULT_LEVEL: &'static LogLevel = &LogLevel::Info;
-/// Logger levels from [Log.jsm]
-/// (https://developer.mozilla.org/en/docs/Mozilla/JavaScript_code_modules/Log.jsm).
-#[derive(Debug, Clone)]
+/// Logger levels from [Log.jsm].
+///
+/// [Log.jsm]: https://developer.mozilla.org/en/docs/Mozilla/JavaScript_code_modules/Log.jsm
+#[derive(Debug, Eq, Clone, Ord, PartialOrd, PartialEq)]
pub enum LogLevel {
- Fatal,
- Error,
- Warn,
- Info,
- Config,
- Debug,
- Trace,
+ Fatal = 70,
+ Error = 60,
+ Warn = 50,
+ Info = 40,
+ Config = 30,
+ Debug = 20,
+ Trace = 10,
}
impl fmt::Display for LogLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match *self {
LogLevel::Fatal => "FATAL",
LogLevel::Error => "ERROR",
LogLevel::Warn => "WARN",
@@ -143,17 +144,37 @@ impl Format for GeckoFormat {
/// Produces a 13-digit Unix Epoch timestamp similar to Gecko.
fn format_ts(ts: DateTime<Local>) -> String {
format!("{}{:03}", ts.timestamp(), ts.timestamp_subsec_millis())
}
#[cfg(test)]
mod tests {
use chrono::Local;
- use super::format_ts;
+ use super::{LogLevel, format_ts};
+
+ #[test]
+ fn test_log_level_cmp() {
+ use self::LogLevel::*;
+
+ assert!(Fatal == Fatal);
+ assert!(Error == Error);
+ assert!(Warn == Warn);
+ assert!(Info == Info);
+ assert!(Config == Config);
+ assert!(Debug == Debug);
+ assert!(Trace == Trace);
+
+ assert!(Fatal > Error);
+ assert!(Error > Warn);
+ assert!(Warn > Info);
+ assert!(Info > Config);
+ assert!(Config > Debug);
+ assert!(Debug > Trace);
+ }
#[test]
fn test_format_ts() {
let ts = Local::now();
let s = format_ts(ts);
assert_eq!(s.len(), 13);
}
}
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -1,14 +1,14 @@
use hyper::method::Method;
use logging;
use logging::LogLevel;
use mozprofile::preferences::Pref;
use mozprofile::profile::Profile;
-use mozrunner::runner::{Runner, FirefoxRunner};
+use mozrunner::runner::{FirefoxRunner, Runner, Stdio};
use regex::Captures;
use rustc_serialize::base64::FromBase64;
use rustc_serialize::json;
use rustc_serialize::json::{Json, ToJson};
use std::collections::BTreeMap;
use std::env;
use std::error::Error;
use std::fs::File;
@@ -453,17 +453,23 @@ impl MarionetteHandler {
// https://developer.mozilla.org/docs/Environment_variables_affecting_crash_reporting
runner.envs().insert("MOZ_CRASHREPORTER".to_string(), "1".to_string());
runner.envs().insert("MOZ_CRASHREPORTER_NO_REPORT".to_string(), "1".to_string());
runner.envs().insert("MOZ_CRASHREPORTER_SHUTDOWN".to_string(), "1".to_string());
if let Some(args) = options.args.take() {
runner.args().extend(args);
- };
+ }
+
+ if let Some(level) = self.current_log_level.take() {
+ if level < LogLevel::Info {
+ runner.stdio = Stdio::Inherit;
+ }
+ }
try!(self.set_prefs(port, &mut runner.profile, custom_profile, options.prefs)
.map_err(|e| {
WebDriverError::new(ErrorStatus::SessionNotCreated,
format!("Failed to set preferences: {}", e))
}));
try!(runner.start()