All Projects → iamcodemaker → console_log

iamcodemaker / console_log

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
A rust logger that routes messages to the browser's console.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to console log

console-log-html
Adds console log output to the screen
Stars: ✭ 25 (-62.69%)
Mutual labels:  console-log
jsxt
The collection of Javascript / JScript / VBScript extensions, tools and more
Stars: ✭ 23 (-65.67%)
Mutual labels:  console-log
badgee
Browser Console Improved
Stars: ✭ 26 (-61.19%)
Mutual labels:  console-log
ptkdev-logger
🦒 Beautiful Logger for Node.js: the best alternative to the console.log statement
Stars: ✭ 117 (+74.63%)
Mutual labels:  console-log
console-logging
Better, prettier commandline logging for Python--with colors! 👻
Stars: ✭ 111 (+65.67%)
Mutual labels:  console-log
babel-plugin-console-source
Add the file name and line numbers to all console logs.
Stars: ✭ 38 (-43.28%)
Mutual labels:  console-log
console-subscriber
Subscribe to the browser's console output.
Stars: ✭ 14 (-79.1%)
Mutual labels:  console-log
ansicolor
A JavaScript ANSI color/style management. ANSI parsing. ANSI to CSS. Small, clean, no dependencies.
Stars: ✭ 91 (+35.82%)
Mutual labels:  console-log
dd.js
Laravel dd() in JS
Stars: ✭ 51 (-23.88%)
Mutual labels:  console-log

console_log Crates.io

A logger that routes messages to the browser's console.

Usage

use log::Level;
fn main() {
    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 = "0.2", features = ["color"] }

The styled log messages will be rendered as follows:

Styled log messages

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.

Cargo.toml

[dependencies]
cfg-if = "0.1"
log = "0.4"
console_log = { version = "0.2", optional = true }

[features]
default = ["console_log"]

lib.rs

use wasm_bindgen::prelude::*;
use cfg_if::cfg_if;

cfg_if! {
    if #[cfg(feature = "console_log")] {
        fn init_log() {
            use log::Level;
            console_log::init_with_level(Level::Trace).expect("error initializing log");
        }
    } else {
        fn init_log() {}
    }
}

#[wasm_bindgen]
pub fn main() {
    init_log();
    // ...
}

Limitations

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.

License

This project is licensed under either of

at your option.

Contributing

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.

See Also

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].