Crates.io | log4wasm |
lib.rs | log4wasm |
version | 0.1.3 |
source | src |
created_at | 2023-07-13 09:08:25.286954 |
updated_at | 2023-07-13 17:26:16.65007 |
description | A stylish rust-generated WebAssembly logging utility. |
homepage | |
repository | https://github.com/heavens/log4wasm |
max_upload_size | |
id | 915160 |
size | 15,662 |
:sparkles: A rust-generated wasm logging utility with styling capabilities for display in a web console.
Be advised that this crate is still considered experimental however should be stable for use in its current state.
You can start using log4wasm
by adding the following in your Cargo.toml [dependencies]
section:
log4wasm = "0.1.3"
Note: log4wasm
relies on the wasm-bindgen crate for code-generation therefore it is the current recommended approach for building reliably.
A minimal use-case within your application would look something like the following:
fn main() {
log4wasm::log::info!("A basic, unformatted log with a level of INFO.");
}
log4wasm
provides a suite of macros out of the box available for use. These may be favorable in instances where building a custom logger is not necessary.
log4wasm::log::trace!("a basic trace log!");
log4wasm::log::debug!("a basic debug log!");
log4wasm::log::info!("a basic info log!");
log4wasm::log::warning!("a basic warn log!");
log4wasm::log::error!("a basic error log!");
log4wasm::log::fatal!("a basic fatal log!");
Alternatively, custom loggers may be created using the designated builder:
use log4wasm::logger::{Level, Logger};
use log4wasm::styled::{Color, Decoration, Styled};
// Create a custom logger with a desired name and log level.
let logger = Logger::new_builder()
.named("MAIN")
.with_level(Level::Debug)
.build();
// Create a styling to be applied on the output written to console.
let styled_log = Styled::with_content(format!("A formatted debug log named \"MAIN\" with green, underlined text and an argument of {}", 1))
.colored(Color::Green)
.decorate(Decoration::Underline)
.into_log();
// Write the styled output to console.
logger.print_fmt(styled_log);