#console-log #console #logging #log

weblog

weblog is a crate that defines a set of macros for calling console.log() and other members of the browser’s console API when targeting Wasm

6 releases (3 breaking)

0.4.0-beta.1 Nov 13, 2020
0.3.0 Oct 19, 2020
0.3.0-beta.1 Oct 2, 2020
0.2.0 Sep 16, 2020
0.1.0 Sep 15, 2020

#386 in WebAssembly

Download history 253/week @ 2024-06-15 202/week @ 2024-06-22 199/week @ 2024-06-29 231/week @ 2024-07-06 246/week @ 2024-07-13 318/week @ 2024-07-20 272/week @ 2024-07-27 239/week @ 2024-08-03 292/week @ 2024-08-10 221/week @ 2024-08-17 218/week @ 2024-08-24 283/week @ 2024-08-31 169/week @ 2024-09-07 143/week @ 2024-09-14 187/week @ 2024-09-21 234/week @ 2024-09-28

774 downloads per month
Used in webru

MIT/Apache

19KB
347 lines

Weblog

Crates.io version docs.rs docs

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 and stdweb 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 &strs:

console_log!(
    "&str",
    "string".to_string(),
    1,
    2.0,
    3f32,
    true,
    false
);

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

# Defaults to web-sys
weblog = "0.3.0"

# For stdweb:
weblog = { version = "0.3.0", default-features = false, features = ["std_web"] }

See the documentation for usage examples.

The crate currently exposes the following macros:

  • console_assert!
  • console_clear!
  • console_count!
  • console_count_reset!
  • console_debug!
  • console_dir!
  • console_dirxml!
  • console_error!
  • console_exception!
  • console_info!
  • console_log!
  • console_table!
  • console_time!
  • console_time_end!
  • console_time_stamp!
  • console_trace!
  • console_warn!

License

Licensed under MIT or Apache-2.

Dependencies

~0–2.6MB
~48K SLoC