Skip to content

s1gtrap/wasm-log

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages