mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Added support in CInitOptions to pass logging/filter modules to VSLogger.
This commit is contained in:
parent
068997cd30
commit
49934c0335
4 changed files with 53 additions and 7 deletions
|
@ -15,8 +15,8 @@ bench = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
simpleservo = { path = "../api" }
|
simpleservo = { path = "../api" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.6"
|
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
env_logger = "0.6"
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
|
|
|
@ -21,6 +21,7 @@ use std::ffi::{CStr, CString};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os::raw::{c_char, c_void};
|
use std::os::raw::{c_char, c_void};
|
||||||
use std::panic::{self, UnwindSafe};
|
use std::panic::{self, UnwindSafe};
|
||||||
|
use std::slice;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
extern "C" fn default_panic_handler(msg: *const c_char) {
|
extern "C" fn default_panic_handler(msg: *const c_char) {
|
||||||
|
@ -222,6 +223,8 @@ pub struct CInitOptions {
|
||||||
pub density: f32,
|
pub density: f32,
|
||||||
pub vr_pointer: *mut c_void,
|
pub vr_pointer: *mut c_void,
|
||||||
pub enable_subpixel_text_antialiasing: bool,
|
pub enable_subpixel_text_antialiasing: bool,
|
||||||
|
pub vslogger_mod_list: *const *const c_char,
|
||||||
|
pub vslogger_mod_size: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The returned string is not freed. This will leak.
|
/// The returned string is not freed. This will leak.
|
||||||
|
@ -231,13 +234,22 @@ pub extern "C" fn servo_version() -> *const c_char {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
fn init_logger() {
|
fn init_logger(modules: &[*const c_char]) {
|
||||||
|
use crate::vslogger::LOG_MODULE_FILTERS;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
use vslogger::VSLogger;
|
use vslogger::VSLogger;
|
||||||
|
|
||||||
static LOGGER: VSLogger = VSLogger;
|
static LOGGER: VSLogger = VSLogger;
|
||||||
static LOGGER_INIT: Once = Once::new();
|
static LOGGER_INIT: Once = Once::new();
|
||||||
|
|
||||||
|
if !modules.is_empty() {
|
||||||
|
*LOG_MODULE_FILTERS.lock().unwrap() = modules
|
||||||
|
.iter()
|
||||||
|
.map(|modules| unsafe { CStr::from_ptr(*modules).to_string_lossy().into_owned() })
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
}
|
||||||
|
|
||||||
LOGGER_INIT.call_once(|| {
|
LOGGER_INIT.call_once(|| {
|
||||||
log::set_logger(&LOGGER)
|
log::set_logger(&LOGGER)
|
||||||
.map(|_| log::set_max_level(LevelFilter::Debug))
|
.map(|_| log::set_max_level(LevelFilter::Debug))
|
||||||
|
@ -246,7 +258,7 @@ fn init_logger() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn init_logger() {
|
fn init_logger(_modules: &[*const c_char]) {
|
||||||
crate::env_logger::init();
|
crate::env_logger::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +270,13 @@ unsafe fn init(
|
||||||
wakeup: extern "C" fn(),
|
wakeup: extern "C" fn(),
|
||||||
callbacks: CHostCallbacks,
|
callbacks: CHostCallbacks,
|
||||||
) {
|
) {
|
||||||
init_logger();
|
let logger_modules = if opts.vslogger_mod_list.is_null() {
|
||||||
|
&[]
|
||||||
|
} else {
|
||||||
|
slice::from_raw_parts(opts.vslogger_mod_list, opts.vslogger_mod_size as usize)
|
||||||
|
};
|
||||||
|
|
||||||
|
init_logger(logger_modules);
|
||||||
|
|
||||||
if let Err(reason) = redirect_stdout_stderr() {
|
if let Err(reason) = redirect_stdout_stderr() {
|
||||||
warn!("Error redirecting stdout/stderr: {}", reason);
|
warn!("Error redirecting stdout/stderr: {}", reason);
|
||||||
|
@ -310,7 +328,6 @@ pub extern "C" fn init_with_egl(
|
||||||
callbacks: CHostCallbacks,
|
callbacks: CHostCallbacks,
|
||||||
) {
|
) {
|
||||||
catch_any_panic(|| {
|
catch_any_panic(|| {
|
||||||
init_logger();
|
|
||||||
let gl = gl_glue::egl::init().unwrap();
|
let gl = gl_glue::egl::init().unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
init(
|
init(
|
||||||
|
@ -333,7 +350,6 @@ pub extern "C" fn init_with_gl(
|
||||||
callbacks: CHostCallbacks,
|
callbacks: CHostCallbacks,
|
||||||
) {
|
) {
|
||||||
catch_any_panic(|| {
|
catch_any_panic(|| {
|
||||||
init_logger();
|
|
||||||
let gl = gl_glue::gl::init().unwrap();
|
let gl = gl_glue::gl::init().unwrap();
|
||||||
unsafe { init(opts, gl, None, None, wakeup, callbacks) }
|
unsafe { init(opts, gl, None, None, wakeup, callbacks) }
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use log::{self, Level, Metadata, Record};
|
use log::{self, Level, Metadata, Record};
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref LOG_MODULE_FILTERS: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(vec![]));
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn OutputDebugStringA(s: *const u8);
|
fn OutputDebugStringA(s: *const u8);
|
||||||
|
@ -12,7 +17,10 @@ pub struct VSLogger;
|
||||||
|
|
||||||
impl log::Log for VSLogger {
|
impl log::Log for VSLogger {
|
||||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||||
metadata.level() <= Level::Warn
|
let modules = LOG_MODULE_FILTERS.lock().unwrap();
|
||||||
|
let is_module_enabled =
|
||||||
|
modules.contains(&String::from(metadata.target())) || modules.is_empty();
|
||||||
|
return metadata.level() <= Level::Warn && is_module_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(&self, record: &Record) {
|
fn log(&self, record: &Record) {
|
||||||
|
|
|
@ -69,6 +69,28 @@ Servo::Servo(hstring url, GLsizei width, GLsizei height, float dpi,
|
||||||
o.enable_subpixel_text_antialiasing = false;
|
o.enable_subpixel_text_antialiasing = false;
|
||||||
o.vr_pointer = NULL;
|
o.vr_pointer = NULL;
|
||||||
|
|
||||||
|
// 7 filter modules.
|
||||||
|
/* Sample list of servo modules to filter.
|
||||||
|
static char *pfilters[] = {
|
||||||
|
"servo",
|
||||||
|
"simpleservo",
|
||||||
|
"simpleservo::jniapi",
|
||||||
|
"simpleservo::gl_glue::egl",
|
||||||
|
// Show JS errors by default.
|
||||||
|
"script::dom::bindings::error",
|
||||||
|
// Show GL errors by default.
|
||||||
|
"canvas::webgl_thread",
|
||||||
|
"compositing::compositor",
|
||||||
|
"constellation::constellation",
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Example Call when *pfilters[] is used:
|
||||||
|
// o.vslogger_mod_list = pfilters; // servo log modules
|
||||||
|
// o.vslogger_mod_size = sizeof(pfilters) / sizeof(pfilters[0]) -1; // Important: Number of modules in pfilters
|
||||||
|
o.vslogger_mod_list = NULL;
|
||||||
|
o.vslogger_mod_size = 0;
|
||||||
|
|
||||||
sServo = this; // FIXME;
|
sServo = this; // FIXME;
|
||||||
|
|
||||||
capi::CHostCallbacks c;
|
capi::CHostCallbacks c;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue