aboutsummaryrefslogtreecommitdiffstats
path: root/components/servo
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-07-15 12:22:26 -0700
committerGitHub <noreply@github.com>2016-07-15 12:22:26 -0700
commita5cd4b95183da4ae9b754d9d4824bd23f4ad7eb8 (patch)
tree5f2f34f706d4eb1290c3ed268492967ab8359afb /components/servo
parentb382cc2103180f7dfd8df9c34970a95ed57a2d88 (diff)
parent44422744ff7f095998b07ded6af8fa0420417405 (diff)
downloadservo-a5cd4b95183da4ae9b754d9d4824bd23f4ad7eb8.tar.gz
servo-a5cd4b95183da4ae9b754d9d4824bd23f4ad7eb8.zip
Auto merge of #11841 - asajeffrey:constellation-logging, r=Manishearth
Send log messages to the constellation <!-- Please describe your changes on the following line: --> Send all warnings and errors to the constellation. Warnings are bufferred up, and included in any subsequent error reports. Errors are reported in the same way as panics. Note that this can't merge yet, as it needs https://github.com/rust-lang-nursery/log/pull/86 to land. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11776 (github issue number if applicable). - [X] These changes do not require tests because we don't test crash reporting. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11841) <!-- Reviewable:end -->
Diffstat (limited to 'components/servo')
-rw-r--r--components/servo/Cargo.lock5
-rw-r--r--components/servo/lib.rs51
-rw-r--r--components/servo/main.rs5
3 files changed, 54 insertions, 7 deletions
diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock
index fffb80f04ea..da1d71b5544 100644
--- a/components/servo/Cargo.lock
+++ b/components/servo/Cargo.lock
@@ -12,7 +12,7 @@ dependencies = [
"constellation 0.0.1",
"devtools 0.0.1",
"devtools_traits 0.0.1",
- "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gaol 0.0.1 (git+https://github.com/servo/gaol)",
"gfx 0.0.1",
@@ -357,6 +357,7 @@ dependencies = [
name = "constellation"
version = "0.0.1"
dependencies = [
+ "backtrace 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
"clipboard 0.1.2 (git+https://github.com/aweinstock314/rust-clipboard)",
@@ -670,7 +671,7 @@ dependencies = [
[[package]]
name = "env_logger"
-version = "0.3.3"
+version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/components/servo/lib.rs b/components/servo/lib.rs
index 8ef09eb066e..20aee632c1d 100644
--- a/components/servo/lib.rs
+++ b/components/servo/lib.rs
@@ -17,10 +17,12 @@
//! The `Browser` is fed events from a generic type that implements the
//! `WindowMethods` trait.
+extern crate env_logger;
#[cfg(not(target_os = "windows"))]
extern crate gaol;
#[macro_use]
extern crate gleam;
+extern crate log;
pub extern crate canvas;
pub extern crate canvas_traits;
@@ -65,10 +67,13 @@ use compositing::{CompositorProxy, IOCompositor};
#[cfg(not(target_os = "windows"))]
use constellation::content_process_sandbox_profile;
use constellation::{Constellation, InitialConstellationState, UnprivilegedPipelineContent};
+use constellation::{FromScriptLogger, FromCompositorLogger};
+use env_logger::Logger as EnvLogger;
#[cfg(not(target_os = "windows"))]
use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{self, IpcSender};
+use log::{Log, LogMetadata, LogRecord};
use net::bluetooth_thread::BluetoothThreadFactory;
use net::image_cache_thread::new_image_cache_thread;
use net::resource_thread::new_resource_threads;
@@ -78,7 +83,8 @@ use profile::mem as profile_mem;
use profile::time as profile_time;
use profile_traits::mem;
use profile_traits::time;
-use script_traits::ConstellationMsg;
+use script_traits::{ConstellationMsg, ScriptMsg};
+use std::cmp::max;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use util::opts;
@@ -100,6 +106,7 @@ pub use gleam::gl;
/// various browser components.
pub struct Browser<Window: WindowMethods + 'static> {
compositor: IOCompositor<Window>,
+ constellation_chan: Sender<ConstellationMsg>,
}
impl<Window> Browser<Window> where Window: WindowMethods + 'static {
@@ -172,7 +179,7 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
let compositor = IOCompositor::create(window, InitialCompositorState {
sender: compositor_proxy,
receiver: compositor_receiver,
- constellation_chan: constellation_chan,
+ constellation_chan: constellation_chan.clone(),
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
webrender: webrender,
@@ -181,6 +188,7 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
Browser {
compositor: compositor,
+ constellation_chan: constellation_chan,
}
}
@@ -199,6 +207,18 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
pub fn request_title_for_main_frame(&self) {
self.compositor.title_for_main_frame()
}
+
+ 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.")
+ }
}
fn create_constellation(opts: opts::Opts,
@@ -244,6 +264,32 @@ fn create_constellation(opts: opts::Opts,
constellation_chan
}
+// A logger that logs to two downstream loggers.
+// This should probably be in the log crate.
+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 {
+ self.0.enabled(metadata) || self.1.enabled(metadata)
+ }
+
+ fn log(&self, record: &LogRecord) {
+ self.0.log(record);
+ self.1.log(record);
+ }
+}
+
+pub fn set_logger(constellation_chan: IpcSender<ScriptMsg>) {
+ log::set_logger(|max_log_level| {
+ let env_logger = EnvLogger::new();
+ let con_logger = FromScriptLogger::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.")
+}
+
/// Content process entry point.
pub fn run_content_process(token: String) {
let (unprivileged_content_sender, unprivileged_content_receiver) =
@@ -255,6 +301,7 @@ pub fn run_content_process(token: String) {
let unprivileged_content = unprivileged_content_receiver.recv().unwrap();
opts::set_defaults(unprivileged_content.opts());
PREFS.extend(unprivileged_content.prefs());
+ set_logger(unprivileged_content.constellation_chan());
// Enter the sandbox if necessary.
if opts::get().sandbox {
diff --git a/components/servo/main.rs b/components/servo/main.rs
index 66f5a149158..954c3f0e848 100644
--- a/components/servo/main.rs
+++ b/components/servo/main.rs
@@ -22,7 +22,6 @@
extern crate android_glue;
#[cfg(not(target_os = "android"))]
extern crate backtrace;
-extern crate env_logger;
// The window backed by glutin
extern crate glutin_app as app;
#[cfg(target_os = "android")]
@@ -96,8 +95,6 @@ fn main() {
};
initiate_panic_hook();
- env_logger::init().unwrap();
-
setup_logging();
if let Some(token) = content_process_token {
@@ -117,6 +114,8 @@ fn main() {
browser: Browser::new(window.clone()),
};
+ browser.browser.setup_logging();
+
register_glutin_resize_handler(&window, &mut browser);
browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]);