Trait ConsoleBackend

Source
pub trait ConsoleBackend: RefUnwindSafe + 'static {
    // Required method
    fn log(&self, level: Level, values: Vec<OwnedJsValue>);
}
Expand description

A console backend that handles console messages sent from JS via console.{log,debug,trace,…} functions.

A backend has to be registered via the ContextBuilder::console method.

A backend that forwads to the log crate is available with the log feature.

Note that any closure of type Fn(Level, Vec<JsValue>) implements this trait.

A very simple logger that just prints to stderr could look like this:

use quickjs_rusty::{Context, OwnedJsValue, console::Level};

Context::builder()
    .console(|level: Level, args: Vec<OwnedJsValue>| {
        eprintln!("{}: {:?}", level, args);
    })
    .build()

Required Methods§

Source

fn log(&self, level: Level, values: Vec<OwnedJsValue>)

Handle a log message.

Implementors§

Source§

impl<F> ConsoleBackend for F
where F: Fn(Level, Vec<OwnedJsValue>) + RefUnwindSafe + 'static,