|
18 | 18 | //! ```
|
19 | 19 | //!
|
20 | 20 | //! # Log Levels
|
21 |
| -//! |
| 21 | +//! |
22 | 22 | //! Rust's log levels map to the browser's console log in the following way.
|
23 |
| -//! |
| 23 | +//! |
24 | 24 | //! | Rust | Web Console |
|
25 | 25 | //! |------------|-------------------|
|
26 | 26 | //! | `trace!()` | `console.debug()` |
|
27 | 27 | //! | `debug!()` | `console.log()` |
|
28 | 28 | //! | `info!()` | `console.info()` |
|
29 | 29 | //! | `warn!()` | `console.warn()` |
|
30 | 30 | //! | `error!()` | `console.error()` |
|
31 |
| -//! |
| 31 | +//! |
32 | 32 | //! # Getting Fancy
|
33 | 33 | //!
|
34 | 34 | //! The feature set provided by this crate is intentionally very basic. If you need more flexible
|
35 | 35 | //! formatting of log messages (timestamps, file and line info, etc.) this crate can be used with
|
36 | 36 | //! the [`fern`] logger via the [`console_log::log`] function.
|
37 | 37 | //!
|
38 | 38 | //! # Code Size
|
39 |
| -//! |
| 39 | +//! |
40 | 40 | //! [Twiggy] reports this library adding about 180Kb to the size of a minimal wasm binary in a
|
41 | 41 | //! debug build. If you want to avoid this, mark the library as optional and conditionally
|
42 | 42 | //! initialize it in your code for non-release builds.
|
43 |
| -//! |
| 43 | +//! |
44 | 44 | //! `Cargo.toml`
|
45 | 45 | //! ```toml
|
46 | 46 | //! [dependencies]
|
47 | 47 | //! cfg_if = "0.1"
|
48 | 48 | //! log = "0.4"
|
49 | 49 | //! console_log = { version = "0.1", optional = true }
|
50 |
| -//! |
| 50 | +//! |
51 | 51 | //! [features]
|
52 | 52 | //! default = ["console_log"]
|
53 | 53 | //! ```
|
54 |
| -//! |
| 54 | +//! |
55 | 55 | //! `lib.rs`
|
56 | 56 | //! ```rust,ignore
|
57 | 57 | //! use wasm_bindgen::prelude::*;
|
|
67 | 67 | //! fn init_log() {}
|
68 | 68 | //! }
|
69 | 69 | //! }
|
70 |
| -//! |
| 70 | +//! |
71 | 71 | //! #[wasm_bindgen]
|
72 | 72 | //! pub fn main() {
|
73 | 73 | //! init_log();
|
74 | 74 | //! // ...
|
75 | 75 | //! }
|
76 | 76 | //! ```
|
77 |
| -//! |
| 77 | +//! |
78 | 78 | //! # Limitations
|
79 |
| -//! |
| 79 | +//! |
80 | 80 | //! The file and line number information associated with the log messages reports locations from
|
81 | 81 | //! the shims generated by `wasm-bindgen`, not the location of the logger call.
|
82 | 82 | //!
|
83 | 83 | //! [Twiggy]: https://github.com/rustwasm/twiggy
|
84 | 84 | //! [`console_log::log`]: fn.log.html
|
85 | 85 | //! [`fern`]: https://docs.rs/fern
|
86 | 86 |
|
87 |
| -use log::{Log, Level, Record, Metadata, SetLoggerError}; |
| 87 | +use log::{Level, Log, Metadata, Record, SetLoggerError}; |
88 | 88 | use web_sys::console;
|
89 | 89 |
|
90 | 90 | static LOGGER: WebConsoleLogger = WebConsoleLogger {};
|
|
0 commit comments