From aca8e1ea5f3e84d68af337fc536fc49be1e6a93a Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 15 May 2014 19:26:14 +0100 Subject: [PATCH 1/3] Do not log CSS parse errors to stderr by default. Fix #2083. Change the log level of CSS errors from error to info. --- src/components/style/errors.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/style/errors.rs b/src/components/style/errors.rs index 38f11904d4b..1abd833fc39 100644 --- a/src/components/style/errors.rs +++ b/src/components/style/errors.rs @@ -26,10 +26,13 @@ impl>> Iterator for ErrorLoggerIterator // Using bool is a work-around for https://github.com/mozilla/rust/issues/13322 local_data_key!(silence_errors: bool) +/// Defaults to a no-op. +/// Set a `RUST_LOG=style::errors` environment variable +/// to log CSS parse errors to stderr. pub fn log_css_error(location: SourceLocation, message: &str) { // TODO eventually this will got into a "web console" or something. if silence_errors.get().is_none() { - error!("{:u}:{:u} {:s}", location.line, location.column, message) + info!("{:u}:{:u} {:s}", location.line, location.column, message) } } From 6a2a080355638651799da0e8cf6c35e68b9b22e5 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 15 May 2014 19:27:31 +0100 Subject: [PATCH 2/3] Remove a workaround for a Rust bug. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve upgraded to a Rust version that fixed mozilla/rust#13322. --- src/components/style/errors.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/style/errors.rs b/src/components/style/errors.rs index 1abd833fc39..b8d811aebd1 100644 --- a/src/components/style/errors.rs +++ b/src/components/style/errors.rs @@ -21,11 +21,6 @@ impl>> Iterator for ErrorLoggerIterator } -// FIXME: go back to `()` instead of `bool` after upgrading Rust -// past 898669c4e203ae91e2048fb6c0f8591c867bccc6 -// Using bool is a work-around for https://github.com/mozilla/rust/issues/13322 -local_data_key!(silence_errors: bool) - /// Defaults to a no-op. /// Set a `RUST_LOG=style::errors` environment variable /// to log CSS parse errors to stderr. @@ -37,8 +32,10 @@ pub fn log_css_error(location: SourceLocation, message: &str) { } +local_data_key!(silence_errors: ()) + pub fn with_errors_silenced(f: || -> T) -> T { - silence_errors.replace(Some(true)); + silence_errors.replace(Some(())); let result = f(); silence_errors.replace(None); result From 4141b776c279431d70141e32af32d1df184e31e1 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 15 May 2014 19:43:04 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Optimize=20CSS=C2=A0error=20logging:=20chec?= =?UTF-8?q?k=20log=20level=20before=20task-local=20silencing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/style/errors.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/style/errors.rs b/src/components/style/errors.rs index b8d811aebd1..215512c8e42 100644 --- a/src/components/style/errors.rs +++ b/src/components/style/errors.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + use cssparser::ast::{SyntaxError, SourceLocation}; @@ -25,9 +26,12 @@ impl>> Iterator for ErrorLoggerIterator /// Set a `RUST_LOG=style::errors` environment variable /// to log CSS parse errors to stderr. pub fn log_css_error(location: SourceLocation, message: &str) { - // TODO eventually this will got into a "web console" or something. - if silence_errors.get().is_none() { - info!("{:u}:{:u} {:s}", location.line, location.column, message) + // Check this first as it’s cheaper than local_data. + if log_enabled!(::log::INFO) { + if silence_errors.get().is_none() { + // TODO eventually this will got into a "web console" or something. + info!("{:u}:{:u} {:s}", location.line, location.column, message) + } } }