You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A logger that routes messages to the browser's console.
Usage
use log::Level;fnmain(){
console_log::init_with_level(Level::Debug);info!("It works!");// ...}
Details
Rust's log levels map to the browser's console log in the following way.
Rust
Web Console
trace!()
console.debug()
debug!()
console.log()
info!()
console.info()
warn!()
console.warn()
error!()
console.error()
Colors
The "color" feature adds styling to the log messages.
Cargo.toml
console_log = { version = "1", features = ["color"] }
The styled log messages will be rendered as follows:
Code Size
Twiggy reports this library adding about
180Kb to the size of a minimal wasm binary in a debug build. If you want to
avoid this, mark the library as optional and conditionally initialize it in
your code for non-release builds.
The file and line number information associated with the log messages reports
locations from the shims generated by wasm-bindgen, not the location of the
logger call.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.