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

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

#452 in WebAssembly

Download history 60/week @ 2022-11-27 49/week @ 2022-12-04 19/week @ 2022-12-11 38/week @ 2022-12-18 77/week @ 2022-12-25 78/week @ 2023-01-01 10/week @ 2023-01-08 39/week @ 2023-01-15 39/week @ 2023-01-22 10/week @ 2023-01-29 16/week @ 2023-02-05 12/week @ 2023-02-12 43/week @ 2023-02-19 8/week @ 2023-02-26 8/week @ 2023-03-05 40/week @ 2023-03-12

102 downloads per month

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

~8.5MB
~169K SLoC