Expand description
weblog is a crate that defines a set of macros for calling console.log()
, console.error()
and other members of the browser’s console API when targeting Wasm.
§Features
- Supports
web-sys
andstdweb
backends with an identical public API - Support for variadic arguments on all calls
- No stringification before sending to the browser - log entire objects and use the full introspective debugging power of the browser console.
§Examples
A simple example.
console_log!("Hello world!");
Passing multiple arguments is fine too.
console_log!("Foo", "bar", "baz");
All of the common browser log levels are supported.
console_debug!("Just testing...");
console_warn!("...but then...");
console_error!("...something bad happened.");
It’s possible to send more than just strings or &str
s:
console_log!(
"&str",
"string".to_string(),
1,
2.0,
3f32,
true,
false,
Some("option"),
);
When using web-sys
crate the macros accept any value that implements the Into<JsValue>
trait. See JsValue for
more details.
No stringification is performed on the Rust side - so objects will be fully introspectable in the browser’s console!
§Usage
By default, the crate assumes the presence of the web-sys
crate.
weblog = "0.3"
If you’d prefer to use it
with stdweb
, enable the feature in Cargo.toml
:
weblog = { version = "0.3", default-features = false, features = ["stdweb"] }
Re-exports§
pub use ::web_sys;
Macros§
- console_
assert - Call the browser’s
console.assert()
function. MDN - console_
clear - Call the browser’s
console.clear()
function. MDN - console_
count - Call the browser’s
console.count()
function. MDN - console_
count_ reset - Call the browser’s
console.countReset()
function. MDN - console_
debug - Call the browser’s
console.debug()
function. MDN - console_
dir - Call the browser’s
console.dir()
function. MDN - console_
dirxml - Call the browser’s
console.dirxml()
function. MDN - console_
error - Call the browser’s
console.error()
function. MDN - console_
exception - Call the browser’s
console.exception()
function. MDN - console_
info - Call the browser’s
console.info()
function. MDN - console_
log - Call the browser’s
console.log()
function. MDN - console_
table - Call the browser’s
console.table()
function. MDN - console_
time - Call the browser’s
console.time()
function. MDN - console_
time_ end - Call the browser’s
console.timeEnd()
function. MDN - console_
time_ log - Call the browser’s
console.timeLog()
function. MDN - console_
time_ stamp - Call the browser’s
console.timeStamp()
function. MDN - console_
trace - Call the browser’s
console.trace()
function. MDN - console_
warn - Call the browser’s
console.warn()
function. MDN