#console-log #logging #console #logger #front-end #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

#262 in Debugging

Download history 6715/week @ 2024-09-02 7377/week @ 2024-09-09 7964/week @ 2024-09-16 11801/week @ 2024-09-23 14344/week @ 2024-09-30 11044/week @ 2024-10-07 13137/week @ 2024-10-14 11668/week @ 2024-10-21 12888/week @ 2024-10-28 10859/week @ 2024-11-04 11170/week @ 2024-11-11 11907/week @ 2024-11-18 11848/week @ 2024-11-25 11243/week @ 2024-12-02 10100/week @ 2024-12-09 9625/week @ 2024-12-16

43,279 downloads per month
Used in 76 crates (53 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

~7.5–10MB
~181K SLoC