#console-log #console #log #logger #front-end #logging

wasm-log

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

1 unstable release

0.3.1 Nov 25, 2022
0.3.0 Nov 25, 2022

#544 in Debugging

Download history 42/week @ 2023-12-19 4/week @ 2023-12-26 10/week @ 2024-01-02 67/week @ 2024-01-09 101/week @ 2024-01-16 26/week @ 2024-01-23 71/week @ 2024-01-30 47/week @ 2024-02-06 23/week @ 2024-02-13 68/week @ 2024-02-20 105/week @ 2024-02-27 49/week @ 2024-03-05 34/week @ 2024-03-12 28/week @ 2024-03-19 36/week @ 2024-03-26 67/week @ 2024-04-02

168 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

21KB
149 lines

wasm-log

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-log = "0.3"

Initialize wasm-log when your app start:

wasm-log::init(wasm-log::Config::default());

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

Log for a specific module only

You can provide a path prefix:

wasm-log::init(wasm-log::Config::default().module_prefix("some::module"));

then, wasm-log 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

~6.5–9MB
~171K SLoC