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

wasm-logger

A logger that sends a message with its Rust source’s line and filename to the browser console

7 releases

0.2.0 Nov 15, 2019
0.1.5 Jun 16, 2019
0.1.3 Apr 13, 2019
0.1.2 Feb 15, 2019
0.1.0 Oct 4, 2018

#83 in WebAssembly

Download history 2049/week @ 2022-03-12 2340/week @ 2022-03-19 2424/week @ 2022-03-26 2489/week @ 2022-04-02 2966/week @ 2022-04-09 2309/week @ 2022-04-16 3035/week @ 2022-04-23 2476/week @ 2022-04-30 2379/week @ 2022-05-07 2629/week @ 2022-05-14 2657/week @ 2022-05-21 2579/week @ 2022-05-28 2440/week @ 2022-06-04 3315/week @ 2022-06-11 2993/week @ 2022-06-18 2178/week @ 2022-06-25

11,295 downloads per month
Used in 38 crates (28 directly)

MIT/Apache

16KB
135 lines

wasm-logger

A logger that sends a message with its Rust source's line and filename to the browser console.

screenshot

Usage

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

Cargo.toml

[dependencies]
log = "0.4.6"
wasm-logger = "0.2.0"

Initialize wasm-logger when your app start:

wasm_logger::init(wasm_logger::Config::default());

// 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::default().module_prefix("some::module"));

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

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
  • 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

~8MB
~159K SLoC