mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
* Upgrade rustc to 1.83 Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix crown (change copied from linked clippy function) Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix named lifetime lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Bump shell.nix Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix non-local impl warnings Signed-off-by: Nico Burns <nico@nicoburns.com> * Format with 1.83 formatting changes Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix manual non-local impl Signed-off-by: Nico Burns <nico@nicoburns.com> * More fixes for crown Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix tidy Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix needless_return lints Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix doc comment lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix missing wait lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow needless_lifetimes lint Signed-off-by: Nico Burns <nico@nicoburns.com> * more doc comments Signed-off-by: Nico Burns <nico@nicoburns.com> * More needless_returns Signed-off-by: Nico Burns <nico@nicoburns.com> * is_empty lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix needless_lifetime lints Signed-off-by: Nico Burns <nico@nicoburns.com> * fix div_ceil lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow non-minimal bool Signed-off-by: Nico Burns <nico@nicoburns.com> * Non-local impl in constellation Signed-off-by: Nico Burns <nico@nicoburns.com> * Missing wait in constellation Signed-off-by: Nico Burns <nico@nicoburns.com> * fmt Signed-off-by: Nico Burns <nico@nicoburns.com> * remove useless lints table Signed-off-by: Nico Burns <nico@nicoburns.com> * Fixup comments Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow non-local definition in sandboxing code to simplify feature flagging Signed-off-by: Nico Burns <nico@nicoburns.com> * Remove wait calls and allow zombie_processes lint Signed-off-by: Nico Burns <nico@nicoburns.com> --------- Signed-off-by: Nico Burns <nico@nicoburns.com>
115 lines
4 KiB
Rust
115 lines
4 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! The constellation uses logging to perform crash reporting.
|
|
//! The constellation receives all `warn!`, `error!` and `panic!` messages,
|
|
//! and generates a crash report when it receives a panic.
|
|
|
|
use std::borrow::ToOwned;
|
|
use std::sync::Arc;
|
|
use std::thread;
|
|
|
|
use backtrace::Backtrace;
|
|
use base::id::TopLevelBrowsingContextId;
|
|
use compositing_traits::ConstellationMsg as FromCompositorMsg;
|
|
use crossbeam_channel::Sender;
|
|
use log::{Level, LevelFilter, Log, Metadata, Record};
|
|
use parking_lot::ReentrantMutex;
|
|
use script_traits::{LogEntry, ScriptMsg as FromScriptMsg, ScriptToConstellationChan};
|
|
|
|
/// A logger directed at the constellation from content processes
|
|
/// #[derive(Clone)]
|
|
pub struct FromScriptLogger {
|
|
/// A channel to the constellation
|
|
pub script_to_constellation_chan: Arc<ReentrantMutex<ScriptToConstellationChan>>,
|
|
}
|
|
|
|
/// A logger directed at the constellation from content processes
|
|
impl FromScriptLogger {
|
|
/// Create a new constellation logger.
|
|
pub fn new(script_to_constellation_chan: ScriptToConstellationChan) -> FromScriptLogger {
|
|
FromScriptLogger {
|
|
script_to_constellation_chan: Arc::new(ReentrantMutex::new(
|
|
script_to_constellation_chan,
|
|
)),
|
|
}
|
|
}
|
|
|
|
/// The maximum log level the constellation logger is interested in.
|
|
pub fn filter(&self) -> LevelFilter {
|
|
LevelFilter::Warn
|
|
}
|
|
}
|
|
|
|
impl Log for FromScriptLogger {
|
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
|
metadata.level() <= Level::Warn
|
|
}
|
|
|
|
fn log(&self, record: &Record) {
|
|
if let Some(entry) = log_entry(record) {
|
|
let thread_name = thread::current().name().map(ToOwned::to_owned);
|
|
let msg = FromScriptMsg::LogEntry(thread_name, entry);
|
|
let chan = self.script_to_constellation_chan.lock();
|
|
let _ = chan.send(msg);
|
|
}
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
/// A logger directed at the constellation from the compositor
|
|
#[derive(Clone)]
|
|
pub struct FromCompositorLogger {
|
|
/// A channel to the constellation
|
|
pub constellation_chan: Arc<ReentrantMutex<Sender<FromCompositorMsg>>>,
|
|
}
|
|
|
|
impl FromCompositorLogger {
|
|
/// Create a new constellation logger.
|
|
pub fn new(constellation_chan: Sender<FromCompositorMsg>) -> FromCompositorLogger {
|
|
FromCompositorLogger {
|
|
constellation_chan: Arc::new(ReentrantMutex::new(constellation_chan)),
|
|
}
|
|
}
|
|
|
|
/// The maximum log level the constellation logger is interested in.
|
|
pub fn filter(&self) -> LevelFilter {
|
|
LevelFilter::Warn
|
|
}
|
|
}
|
|
|
|
impl Log for FromCompositorLogger {
|
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
|
metadata.level() <= Level::Warn
|
|
}
|
|
|
|
fn log(&self, record: &Record) {
|
|
if let Some(entry) = log_entry(record) {
|
|
let top_level_id = TopLevelBrowsingContextId::installed();
|
|
let thread_name = thread::current().name().map(ToOwned::to_owned);
|
|
let msg = FromCompositorMsg::LogEntry(top_level_id, thread_name, entry);
|
|
let chan = self.constellation_chan.lock();
|
|
let _ = chan.send(msg);
|
|
}
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
/// 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 `Record` does not implement serde (de)serialization,
|
|
/// so cannot be used over an IPC channel.
|
|
fn log_entry(record: &Record) -> Option<LogEntry> {
|
|
match record.level() {
|
|
Level::Error if thread::panicking() => Some(LogEntry::Panic(
|
|
format!("{}", record.args()),
|
|
format!("{:?}", Backtrace::new()),
|
|
)),
|
|
Level::Error => Some(LogEntry::Error(format!("{}", record.args()))),
|
|
Level::Warn => Some(LogEntry::Warn(format!("{}", record.args()))),
|
|
_ => None,
|
|
}
|
|
}
|