A pretty logger for wasm front-end app based on wasm-bindgen
Cargo.toml
[dependencies]
log = "0.4"
wasm-logger = "0.1.2"
```rust
extern crate log; extern crate wasm_logger; ```
Initialize wasm-logger
when your app start:
```rust
wasmlogger::init(wasmlogger::Config::new(log::Level::Debug));
// Logging info!("Some info"); error!("Error message"); ```
In Rust 2018 you don't have to extern crate
, just initialize wasm-logger
when your app start:
```rust
wasmlogger::init(wasmlogger::Config::new(log::Level::Debug));
// Logging log::info!("Some info"); log::error!("Error message"); ```
You can provide a path prefix:
rust
wasm_logger::init(wasm_logger::Config::with_prefix(log::Level::Debug, "some::module"));
then, wasm-logger
only logs message from some::module
For more information about how to use loggers in Rust, see log.
log
to console's methodslog::error!
, log::warn!
and log::info!
call theirs equivalent methods of the browser console. The console.trace
method outputs some extra trace from the generated JS glue code which we don't want. Therefore, we choose to map log::debug!
to console.log
and log::trace!
to console.debug
.
Chromium/Chrome filters out console.debug
(execute by log::trace!
) by default. You must check the Verbose
filter in your browser console to see trace entries.
MIT or Apache-2.0