Skip to main content

weblog/
lib.rs

1//! weblog is a crate that defines a set of macros for calling `console.log()`, `console.error()`
2//! and other members of the browser's console API when targeting Wasm.
3//!
4//! # Features
5//!
6//! * Supports `web-sys` and `stdweb` backends with an identical public API
7//! * Support for variadic arguments on all calls
8//! * No stringification before sending to the browser - log entire objects and use the full
9//! introspective debugging power of the browser console.
10//!
11//! # Examples
12//!
13//! A simple example.
14//!
15//! ```
16//! # #[macro_use] extern crate weblog;
17//! # fn main() {
18//! console_log!("Hello world!");
19//! # }
20//! ```
21//! Passing multiple arguments is fine too.
22//!
23//! ```
24//! # #[macro_use] extern crate weblog;
25//! # fn main() {
26//! console_log!("Foo", "bar", "baz");
27//! # }
28//! ```
29//! All of the common browser log levels are supported.
30//!
31//! ```
32//! # #[macro_use] extern crate weblog;
33//! # fn main() {
34//! console_debug!("Just testing...");
35//! console_warn!("...but then...");
36//! console_error!("...something bad happened.");
37//! # }
38//! ```
39//! It's possible to send more than just strings or `&str`s:
40//!
41//! ```
42//! # #[macro_use] extern crate weblog;
43//! # fn main() {
44//! console_log!(
45//!     "&str",
46//!     "string".to_string(),
47//!     1,
48//!     2.0,
49//!     3f32,
50//!     true,
51//!     false,
52//!     Some("option"),
53//! );
54//! # }
55//! ```
56//! When using `web-sys` crate the macros accept any value that implements the `Into<JsValue>` trait. See [JsValue](https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen/struct.JsValue.html) for
57//! more details.
58//!
59//! No stringification is performed on the Rust side - so objects will be fully introspectable in
60//! the browser's console!
61//!
62//! # Usage
63//!
64//! By default, the crate assumes the presence of the `web-sys` crate.
65//!
66//! ```toml
67//! weblog = "0.3"
68//! ```
69//!
70//!
71//! If you'd prefer to use it
72//! with `stdweb`, enable the feature in `Cargo.toml`:
73//!
74//! ```toml
75//! weblog = { version = "0.3", default-features = false, features = ["stdweb"] }
76//! ```
77//!
78mod console;
79
80#[cfg(feature = "web_sys")]
81pub use weblog_proc_macro::*;
82
83#[cfg(feature = "web_sys")]
84pub use ::web_sys;
85
86#[cfg(feature = "std_web")]
87pub use self::console::std_web::*;