pub struct ConsoleLogger(/* private fields */);Expand description
A logger used to output logs to the web console.
Implementations§
Source§impl ConsoleLogger
impl ConsoleLogger
Sourcepub fn init(level: Option<LogLevel>) -> Self
pub fn init(level: Option<LogLevel>) -> Self
Initializes the global logger, when level is None, the default value
will be used, which is Info.
When Level is Some(LogLevel::Off), initialization will not be performed.
§Example
§Configure in Rust:
src/lib.rs
use clg::log_level::LogLevel;
use clg::ConsoleLogger;
#[wasm_bindgen]
pub fn init_logger() {
ConsoleLogger::init(Some(LogLevel::Debug));
}js/index.cjs
const wasm = require("./pkg/[custom-wasm-glue].js");
const _init = wasm.init_logger();
wasm.__clgTestLogger();Within the same thread, the logger can only be initialized once. If you choose to initialize in js, do not call
init_logger()in rust.
§Configure in Javascript:
src/lib.rs
#[allow(unused_imports)]
use clg::ConsoleLogger as _;js/index.cjs
const wasm = require("./pkg/[custom-wasm-glue].js");
const lv = wasm._clgNewLogLevel("info");
const _init = new wasm._clgConsoleLogger(lv);
wasm.__clgTestLogger();Sourcepub fn get_level_num(&self) -> usize
pub fn get_level_num(&self) -> usize
Gets the Log Level (usize)
Off =>0,
Error =>1,
Warn =>2,
Info =>3,
Debug =>4,
Trace =>5Sourcepub fn output(level: u8, content: JsValue)
pub fn output(level: u8, content: JsValue)
Calls the specified console function according to log_level.
error => console.error(msg),
warn => console.warn(msg),
info | debug => console.info(msg),
trace => console.trace(msg)log::Level as u8 => 1..=5
Since some browsers don’t support console.debug(), use console.info()
when level == debug
§Example
let lv = LogLevel::Debug;
output(lv as _, "dbg message")Methods from Deref<Target = LevelFilter>§
Sourcepub fn to_level(&self) -> Option<Level>
pub fn to_level(&self) -> Option<Level>
Converts self to the equivalent Level.
Returns None if self is LevelFilter::Off.
Sourcepub fn as_str(&self) -> &'static str
pub fn as_str(&self) -> &'static str
Returns the string representation of the LevelFilter.
This returns the same string as the fmt::Display implementation.
Sourcepub fn increment_severity(&self) -> LevelFilter
pub fn increment_severity(&self) -> LevelFilter
Get the next-highest LevelFilter from this one.
If the current LevelFilter is at the highest level, the returned LevelFilter will be the
same as the current one.
§Examples
use log::LevelFilter;
let level_filter = LevelFilter::Info;
assert_eq!(LevelFilter::Debug, level_filter.increment_severity());
assert_eq!(LevelFilter::Trace, level_filter.increment_severity().increment_severity());
assert_eq!(LevelFilter::Trace, level_filter.increment_severity().increment_severity().increment_severity()); // max levelSourcepub fn decrement_severity(&self) -> LevelFilter
pub fn decrement_severity(&self) -> LevelFilter
Get the next-lowest LevelFilter from this one.
If the current LevelFilter is at the lowest level, the returned LevelFilter will be the
same as the current one.
§Examples
use log::LevelFilter;
let level_filter = LevelFilter::Info;
assert_eq!(LevelFilter::Warn, level_filter.decrement_severity());
assert_eq!(LevelFilter::Error, level_filter.decrement_severity().decrement_severity());
assert_eq!(LevelFilter::Off, level_filter.decrement_severity().decrement_severity().decrement_severity());
assert_eq!(LevelFilter::Off, level_filter.decrement_severity().decrement_severity().decrement_severity().decrement_severity()); // min levelTrait Implementations§
Source§impl Clone for ConsoleLogger
impl Clone for ConsoleLogger
Source§fn clone(&self) -> ConsoleLogger
fn clone(&self) -> ConsoleLogger
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConsoleLogger
impl Debug for ConsoleLogger
Source§impl Default for ConsoleLogger
impl Default for ConsoleLogger
Source§impl Deref for ConsoleLogger
impl Deref for ConsoleLogger
Source§impl From<ConsoleLogger> for JsValue
impl From<ConsoleLogger> for JsValue
Source§fn from(value: ConsoleLogger) -> Self
fn from(value: ConsoleLogger) -> Self
Source§impl FromWasmAbi for ConsoleLogger
impl FromWasmAbi for ConsoleLogger
Source§impl Hash for ConsoleLogger
impl Hash for ConsoleLogger
Source§impl IntoWasmAbi for ConsoleLogger
impl IntoWasmAbi for ConsoleLogger
Source§impl Log for ConsoleLogger
impl Log for ConsoleLogger
Source§impl LongRefFromWasmAbi for ConsoleLogger
impl LongRefFromWasmAbi for ConsoleLogger
Source§impl OptionFromWasmAbi for ConsoleLogger
impl OptionFromWasmAbi for ConsoleLogger
Source§impl OptionIntoWasmAbi for ConsoleLogger
impl OptionIntoWasmAbi for ConsoleLogger
Source§impl Ord for ConsoleLogger
impl Ord for ConsoleLogger
Source§fn cmp(&self, other: &ConsoleLogger) -> Ordering
fn cmp(&self, other: &ConsoleLogger) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ConsoleLogger
impl PartialEq for ConsoleLogger
Source§impl PartialOrd for ConsoleLogger
impl PartialOrd for ConsoleLogger
Source§impl RefFromWasmAbi for ConsoleLogger
impl RefFromWasmAbi for ConsoleLogger
Source§type Anchor = RcRef<ConsoleLogger>
type Anchor = RcRef<ConsoleLogger>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for ConsoleLogger
impl RefMutFromWasmAbi for ConsoleLogger
Source§impl TryFromJsValue for ConsoleLogger
impl TryFromJsValue for ConsoleLogger
Source§impl VectorFromWasmAbi for ConsoleLogger
impl VectorFromWasmAbi for ConsoleLogger
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[ConsoleLogger]>
Source§impl VectorIntoWasmAbi for ConsoleLogger
impl VectorIntoWasmAbi for ConsoleLogger
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[ConsoleLogger]>) -> Self::Abi
Source§impl WasmDescribeVector for ConsoleLogger
impl WasmDescribeVector for ConsoleLogger
impl Copy for ConsoleLogger
impl Eq for ConsoleLogger
impl StructuralPartialEq for ConsoleLogger
impl SupportsConstructor for ConsoleLogger
impl SupportsInstanceProperty for ConsoleLogger
impl SupportsStaticProperty for ConsoleLogger
Auto Trait Implementations§
impl Freeze for ConsoleLogger
impl RefUnwindSafe for ConsoleLogger
impl Send for ConsoleLogger
impl Sync for ConsoleLogger
impl Unpin for ConsoleLogger
impl UnwindSafe for ConsoleLogger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read moreSource§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
Source§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
Source§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
Source§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.