Skip to content

Commit

Permalink
Bump env_logger to 0.5 and log to 0.4 in every servo crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Eijebong committed Mar 28, 2018
1 parent 84513d4 commit 0918ac8
Show file tree
Hide file tree
Showing 34 changed files with 153 additions and 110 deletions.
102 changes: 69 additions & 33 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/canvas/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ euclid = "0.17"
fnv = "1.0"
gleam = "0.4.29"
ipc-channel = "0.10"
log = "0.3.5"
log = "0.4"
num-traits = "0.1.32"
offscreen_gl_context = { version = "0.15", features = ["serde", "osmesa"] }
serde_bytes = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion components/compositing/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ gleam = "0.4.29"
image = "0.18"
ipc-channel = "0.10"
libc = "0.2"
log = "0.3.5"
log = "0.4"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"}
Expand Down
4 changes: 2 additions & 2 deletions components/config/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ doctest = false
euclid = "0.17"
getopts = "0.2.11"
lazy_static = "1"
log = "0.3.5"
log = "0.4"
num_cpus = "1.1.0"
rustc-serialize = "0.3"
serde = "1.0"
Expand All @@ -24,7 +24,7 @@ servo_url = {path = "../url"}
url = "1.2"

[dev-dependencies]
env_logger = "0.4"
env_logger = "0.5"

[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies]
xdg = "2.0"
Expand Down
2 changes: 1 addition & 1 deletion components/constellation/Cargo.toml
Expand Up @@ -25,7 +25,7 @@ hyper = "0.10"
ipc-channel = "0.10"
itertools = "0.7"
layout_traits = {path = "../layout_traits"}
log = "0.3.5"
log = "0.4"
metrics = {path = "../metrics"}
msg = {path = "../msg"}
net = {path = "../net"}
Expand Down
38 changes: 21 additions & 17 deletions components/constellation/constellation.rs
Expand Up @@ -111,7 +111,7 @@ use ipc_channel::ipc::{self, IpcSender, IpcReceiver};
use ipc_channel::router::ROUTER;
use itertools::Itertools;
use layout_traits::LayoutThreadFactory;
use log::{Log, LogLevel, LogLevelFilter, LogMetadata, LogRecord};
use log::{Log, Level, LevelFilter, Metadata, Record};
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, PipelineId};
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, TraversalDirection};
Expand Down Expand Up @@ -438,17 +438,17 @@ impl FromScriptLogger {
}

/// The maximum log level the constellation logger is interested in.
pub fn filter(&self) -> LogLevelFilter {
LogLevelFilter::Warn
pub fn filter(&self) -> LevelFilter {
LevelFilter::Warn
}
}

impl Log for FromScriptLogger {
fn enabled(&self, metadata: &LogMetadata) -> bool {
metadata.level() <= LogLevel::Warn
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= Level::Warn
}

fn log(&self, record: &LogRecord) {
fn log(&self, record: &Record) {
if let Some(entry) = log_entry(record) {
debug!("Sending log entry {:?}.", entry);
let thread_name = thread::current().name().map(ToOwned::to_owned);
Expand All @@ -457,6 +457,8 @@ impl Log for FromScriptLogger {
let _ = chan.send(msg);
}
}

fn flush(&self) {}
}

/// A logger directed at the constellation from the compositor
Expand All @@ -475,17 +477,17 @@ impl FromCompositorLogger {
}

/// The maximum log level the constellation logger is interested in.
pub fn filter(&self) -> LogLevelFilter {
LogLevelFilter::Warn
pub fn filter(&self) -> LevelFilter {
LevelFilter::Warn
}
}

impl Log for FromCompositorLogger {
fn enabled(&self, metadata: &LogMetadata) -> bool {
metadata.level() <= LogLevel::Warn
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= Level::Warn
}

fn log(&self, record: &LogRecord) {
fn log(&self, record: &Record) {
if let Some(entry) = log_entry(record) {
debug!("Sending log entry {:?}.", entry);
let top_level_id = TopLevelBrowsingContextId::installed();
Expand All @@ -495,22 +497,24 @@ impl Log for FromCompositorLogger {
let _ = chan.send(msg);
}
}

fn flush(&self) {}
}

/// Rust uses `LogRecord` for storing logging, but servo converts that to
/// Rust uses `Record` for storing logging, but servo converts that to
/// a `LogEntry`. We do this so that we can record panics as well as log
/// messages, and because `LogRecord` does not implement serde (de)serialization,
/// messages, and because `Record` does not implement serde (de)serialization,
/// so cannot be used over an IPC channel.
fn log_entry(record: &LogRecord) -> Option<LogEntry> {
fn log_entry(record: &Record) -> Option<LogEntry> {
match record.level() {
LogLevel::Error if thread::panicking() => Some(LogEntry::Panic(
Level::Error if thread::panicking() => Some(LogEntry::Panic(
format!("{}", record.args()),
format!("{:?}", Backtrace::new())
)),
LogLevel::Error => Some(LogEntry::Error(
Level::Error => Some(LogEntry::Error(
format!("{}", record.args())
)),
LogLevel::Warn => Some(LogEntry::Warn(
Level::Warn => Some(LogEntry::Warn(
format!("{}", record.args())
)),
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion components/debugger/Cargo.toml
Expand Up @@ -11,5 +11,5 @@ path = "lib.rs"
crate_type = ["rlib"]

[dependencies]
log = "0.3.5"
log = "0.4"
ws = "0.7.3"
2 changes: 1 addition & 1 deletion components/devtools/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ devtools_traits = {path = "../devtools_traits"}
hyper = "0.10"
hyper_serde = "0.8"
ipc-channel = "0.10"
log = "0.3.5"
log = "0.4"
msg = {path = "../msg"}
serde = "1.0"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion components/gfx/Cargo.toml
Expand Up @@ -26,7 +26,7 @@ harfbuzz-sys = "0.1"
ipc-channel = "0.10"
lazy_static = "1"
libc = "0.2"
log = "0.3.5"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
msg = {path = "../msg"}
Expand Down
2 changes: 1 addition & 1 deletion components/layout/Cargo.toml
Expand Up @@ -23,7 +23,7 @@ gfx_traits = {path = "../gfx_traits"}
html5ever = "0.22"
ipc-channel = "0.10"
libc = "0.2"
log = "0.3.5"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
Expand Down
2 changes: 1 addition & 1 deletion components/layout_thread/Cargo.toml
Expand Up @@ -26,7 +26,7 @@ layout = {path = "../layout"}
layout_traits = {path = "../layout_traits"}
lazy_static = "1"
libc = "0.2"
log = "0.3.5"
log = "0.4"
time = "0.1.17"
malloc_size_of = { path = "../malloc_size_of" }
metrics = {path = "../metrics"}
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ path = "lib.rs"
[dependencies]
gfx_traits = {path = "../gfx_traits"}
ipc-channel = "0.10"
log = "0.3.5"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
msg = {path = "../msg"}
Expand Down
2 changes: 1 addition & 1 deletion components/net/Cargo.toml
Expand Up @@ -23,7 +23,7 @@ hyper-openssl = "0.2.2"
immeta = "0.3.6"
ipc-channel = "0.10"
lazy_static = "1"
log = "0.3.5"
log = "0.4"
matches = "0.1"
mime = "0.2.1"
mime_guess = "1.8.0"
Expand Down
4 changes: 2 additions & 2 deletions components/net/http_loader.rs
Expand Up @@ -410,7 +410,7 @@ fn obtain_response(connector: &Pool<Connector>,
}
}

if log_enabled!(log::LogLevel::Info) {
if log_enabled!(log::Level::Info) {
info!("{} {}", method, url);
for header in headers.iter() {
info!(" - {}", header);
Expand Down Expand Up @@ -1069,7 +1069,7 @@ fn http_network_fetch(request: &Request,
Err(error) => return Response::network_error(error),
};

if log_enabled!(log::LogLevel::Info) {
if log_enabled!(log::Level::Info) {
info!("response for {}", url);
for header in res.headers.iter() {
info!(" - {}", header);
Expand Down
2 changes: 1 addition & 1 deletion components/net_traits/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ hyper_serde = "0.8"
image = "0.18"
ipc-channel = "0.10"
lazy_static = "1"
log = "0.3.5"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
msg = {path = "../msg"}
Expand Down
2 changes: 1 addition & 1 deletion components/profile/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ profile_traits = {path = "../profile_traits"}
influent = "0.4"
ipc-channel = "0.10"
heartbeats-simple = "0.4"
log = "0.3.5"
log = "0.4"
serde = "1.0"
serde_json = "1.0"
servo_config = {path = "../config"}
Expand Down
2 changes: 1 addition & 1 deletion components/profile_traits/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ bincode = "1"
energy-monitor = {version = "0.2.0", optional = true}
energymon = {git = "https://github.com/energymon/energymon-rust.git", optional = true}
ipc-channel = "0.10"
log = "0.3.5"
log = "0.4"
serde = "1.0"
servo_config = {path = "../config"}
signpost = {git = "https://github.com/pcwalton/signpost.git"}
Expand Down
2 changes: 1 addition & 1 deletion components/rand/Cargo.toml
Expand Up @@ -11,6 +11,6 @@ path = "lib.rs"

[dependencies]
lazy_static = "1"
log = "0.3"
log = "0.4"
rand = "0.4"
uuid = "0.6.2"
2 changes: 1 addition & 1 deletion components/remutex/Cargo.toml
Expand Up @@ -13,5 +13,5 @@ doctest = false

[dependencies]
lazy_static = "1"
log = "0.3.5"
log = "0.4"
nonzero = {path = "../nonzero"}
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -55,7 +55,7 @@ ipc-channel = "0.10"
jstraceable_derive = {path = "../jstraceable_derive"}
lazy_static = "1"
libc = "0.2"
log = "0.3.5"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
metrics = {path = "../metrics"}
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ gfx_traits = {path = "../gfx_traits"}
html5ever = "0.22"
ipc-channel = "0.10"
libc = "0.2"
log = "0.3.5"
log = "0.4"
time = "0.1.17"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/reporter.rs
Expand Up @@ -26,7 +26,7 @@ impl ParseErrorReporter for CSSErrorReporter {
url: &ServoUrl,
location: SourceLocation,
error: ContextualParseError) {
if log_enabled!(log::LogLevel::Info) {
if log_enabled!(log::Level::Info) {
info!("Url:\t{}\n{}:{} {}",
url.as_str(),
location.line,
Expand Down
2 changes: 1 addition & 1 deletion components/selectors/Cargo.toml
Expand Up @@ -23,7 +23,7 @@ bench = []
bitflags = "1.0"
matches = "0.1"
cssparser = "0.23.0"
log = "0.3"
log = "0.4"
fnv = "1.0"
phf = "0.7.18"
precomputed-hash = "0.1"
Expand Down
4 changes: 2 additions & 2 deletions components/servo/Cargo.toml
Expand Up @@ -37,13 +37,13 @@ constellation = {path = "../constellation"}
debugger = {path = "../debugger"}
devtools = {path = "../devtools"}
devtools_traits = {path = "../devtools_traits"}
env_logger = "0.4"
env_logger = "0.5"
euclid = "0.17"
gfx = {path = "../gfx"}
gleam = "0.4.29"
ipc-channel = "0.10"
layout_thread = {path = "../layout_thread"}
log = "0.3"
log = "0.4"
msg = {path = "../msg"}
net = {path = "../net"}
net_traits = {path = "../net_traits"}
Expand Down
43 changes: 23 additions & 20 deletions components/servo/lib.rs
Expand Up @@ -79,13 +79,13 @@ use constellation::{Constellation, InitialConstellationState, UnprivilegedPipeli
use constellation::{FromCompositorLogger, FromScriptLogger};
#[cfg(all(not(target_os = "windows"), not(target_os = "ios")))]
use constellation::content_process_sandbox_profile;
use env_logger::Logger as EnvLogger;
use env_logger::Builder as EnvLoggerBuilder;
use euclid::Length;
#[cfg(all(not(target_os = "windows"), not(target_os = "ios")))]
use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{self, IpcSender};
use log::{Log, LogMetadata, LogRecord};
use log::{Log, Metadata, Record};
use net::resource_thread::new_resource_threads;
use net_traits::IpcSend;
use profile::mem as profile_mem;
Expand Down Expand Up @@ -404,14 +404,13 @@ impl<Window> Servo<Window> where Window: WindowMethods + 'static {

pub fn setup_logging(&self) {
let constellation_chan = self.constellation_chan.clone();
log::set_logger(|max_log_level| {
let env_logger = EnvLogger::new();
let con_logger = FromCompositorLogger::new(constellation_chan);
let filter = max(env_logger.filter(), con_logger.filter());
let logger = BothLogger(env_logger, con_logger);
max_log_level.set(filter);
Box::new(logger)
}).expect("Failed to set logger.")
let env_logger = EnvLoggerBuilder::new().build();
let con_logger = FromCompositorLogger::new(constellation_chan);
let filter = max(env_logger.filter(), con_logger.filter());
log::set_max_level(filter);

let logger = BothLogger(env_logger, con_logger);
log::set_boxed_logger(Box::new(logger)).expect("Failed to set logger.");
}

pub fn deinit(self) {
Expand Down Expand Up @@ -548,25 +547,29 @@ fn create_constellation(user_agent: Cow<'static, str>,
struct BothLogger<Log1, Log2>(Log1, Log2);

impl<Log1, Log2> Log for BothLogger<Log1, Log2> where Log1: Log, Log2: Log {
fn enabled(&self, metadata: &LogMetadata) -> bool {
fn enabled(&self, metadata: &Metadata) -> bool {
self.0.enabled(metadata) || self.1.enabled(metadata)
}

fn log(&self, record: &LogRecord) {
fn log(&self, record: &Record) {
self.0.log(record);
self.1.log(record);
}

fn flush(&self) {
self.0.flush();
self.1.flush();
}
}

pub fn set_logger(script_to_constellation_chan: ScriptToConstellationChan) {
log::set_logger(|max_log_level| {
let env_logger = EnvLogger::new();
let con_logger = FromScriptLogger::new(script_to_constellation_chan);
let filter = max(env_logger.filter(), con_logger.filter());
let logger = BothLogger(env_logger, con_logger);
max_log_level.set(filter);
Box::new(logger)
}).expect("Failed to set logger.")
let env_logger = EnvLoggerBuilder::new().build();
let con_logger = FromScriptLogger::new(script_to_constellation_chan);
let filter = max(env_logger.filter(), con_logger.filter());
log::set_max_level(filter);

let logger = BothLogger(env_logger, con_logger);
log::set_boxed_logger(Box::new(logger)).expect("Failed to set logger.");
}

/// Content process entry point.
Expand Down

0 comments on commit 0918ac8

Please sign in to comment.