#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

#512 in Debugging

Download history 27/week @ 2024-05-04 40/week @ 2024-05-11 59/week @ 2024-05-18 48/week @ 2024-05-25 62/week @ 2024-06-01 73/week @ 2024-06-08 157/week @ 2024-06-15 52/week @ 2024-06-22 58/week @ 2024-06-29 150/week @ 2024-07-06 975/week @ 2024-07-13 1256/week @ 2024-07-20 1339/week @ 2024-07-27 269/week @ 2024-08-03 149/week @ 2024-08-10 118/week @ 2024-08-17

2,093 downloads per month
Used in 3 crates (2 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

~7–9.5MB
~176K SLoC