#wasm #front-end #logger #console #log

wasm-logger

A pretty logger for wasm front-end app written in Rust

3 releases

✓ Uses Rust 2018 edition

new 0.1.2 Feb 15, 2019
0.1.1 Jan 11, 2019
0.1.0 Oct 4, 2018

#22 in #logger

Download history 12/week @ 2018-11-01 4/week @ 2018-11-08 2/week @ 2018-11-15 2/week @ 2018-11-22 13/week @ 2018-11-29 5/week @ 2018-12-06 8/week @ 2018-12-13 43/week @ 2018-12-20 1/week @ 2018-12-27 8/week @ 2019-01-03 22/week @ 2019-01-10 9/week @ 2019-01-17 6/week @ 2019-01-24 3/week @ 2019-01-31 2/week @ 2019-02-07

42 downloads per month

MIT/Apache

7KB
109 lines

wasm-logger

A pretty logger for wasm front-end app based on wasm-bindgen

Cargo.toml

[dependencies]
log = "0.4"
wasm-logger = "0.1.2"

Rust 2015

#[macro_use]
extern crate log;
extern crate wasm_logger;

Initialize wasm-logger when your app start:

wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));

// Logging
info!("Some info");
error!("Error message");

Rust 2018

In Rust 2018 you don't have to extern crate, just initialize wasm-logger when your app start:

wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));

// Logging
log::info!("Some info");
log::error!("Error message");

Log for a specific module only

You can provide a path prefix:

wasm_logger::init(wasm_logger::Config::with_prefix(log::Level::Debug, "some::module"));

then, wasm-logger only logs message from some::module

Logging in Rust

For more information about how to use loggers in Rust, see log.

Mapping from log to console's methods

log::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.

Note for Chromium/Chrome users

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.

License

MIT or Apache-2.0

Dependencies

~2MB
~33K SLoC