Skip to main content

LogLazy

Struct LogLazy 

Source
pub struct LogLazy { /* private fields */ }
Expand description

Logger instance with a mutable bitmask and lazy message evaluation.

Implementations§

Source§

impl LogLazy

Source

pub fn new() -> Self

Creates a logger with the default info level.

Source

pub fn with_options(options: LogLazyOptions) -> Self

Creates a logger from the extensible options API.

Source

pub fn with_level<'a, L>(level: L) -> Self
where L: Into<LevelSpec<'a>>,

Creates a logger with a custom level.

Examples found in repository?
examples/basic_usage.rs (line 4)
3fn main() {
4    let log = LogLazy::with_level(levels::PRODUCTION);
5
6    log.error(|| "database connection failed");
7
8    debug_lazy!(log, "expensive debug payload: {}", build_debug_payload());
9    error_lazy!(log, "request failed for user {}", 42);
10}
Source

pub fn with_level_and_presets<'a, L, I, S>(level: L, presets: I) -> Self
where L: Into<LevelSpec<'a>>, I: IntoIterator<Item = (S, LevelMask)>, S: Into<String>,

Creates a logger with a custom level and custom presets.

Source

pub fn with_sink<'a, L, F>(level: L, sink: F) -> Self
where L: Into<LevelSpec<'a>>, F: Fn(Level, String) + Send + Sync + 'static,

Creates a logger with a custom sink.

Source

pub fn add_preset(&mut self, name: impl Into<String>, mask: LevelMask)

Adds or replaces a named preset.

Source

pub const fn level(&self) -> LevelMask

Returns the active level bitmask.

Source

pub fn set_level<'a, L>(&mut self, level: L)
where L: Into<LevelSpec<'a>>,

Sets the active level bitmask.

Source

pub fn level_or_default<'a, L>(&self, level: L, default: LevelMask) -> LevelMask
where L: Into<LevelSpec<'a>>,

Resolves a string or numeric level to a mask, falling back to default.

Source

pub fn should_log<'a, L>(&self, level: L) -> bool
where L: Into<LevelSpec<'a>>,

Checks whether a level is currently enabled.

Source

pub fn enable_level<'a, L>(&mut self, level: L)
where L: Into<LevelSpec<'a>>,

Enables one level bit or mask.

Source

pub fn disable_level<'a, L>(&mut self, level: L)
where L: Into<LevelSpec<'a>>,

Disables one level bit or mask.

Source

pub fn get_enabled_levels(&self) -> Vec<&'static str>

Returns enabled standard level names in stable order.

Source

pub fn log<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Logs at the default info level.

Source

pub fn emit<'a, L, F, M>(&self, level: L, message: F)
where L: Into<LevelSpec<'a>>, F: FnOnce() -> M, M: Display,

Logs at an explicit level.

Source

pub fn emit_args<'a, L, I>(&self, level: L, args: I)
where L: Into<LevelSpec<'a>>, I: IntoIterator<Item = LogArg>,

Logs explicit lazy arguments at an explicit level.

Source

pub fn fatal<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Source

pub fn error<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Examples found in repository?
examples/basic_usage.rs (line 6)
3fn main() {
4    let log = LogLazy::with_level(levels::PRODUCTION);
5
6    log.error(|| "database connection failed");
7
8    debug_lazy!(log, "expensive debug payload: {}", build_debug_payload());
9    error_lazy!(log, "request failed for user {}", 42);
10}
Source

pub fn warn<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Source

pub fn info<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Source

pub fn debug<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Source

pub fn verbose<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Source

pub fn trace<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Source

pub fn silly<F, M>(&self, message: F)
where F: FnOnce() -> M, M: Display,

Trait Implementations§

Source§

impl Clone for LogLazy

Source§

fn clone(&self) -> LogLazy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LogLazy

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LogLazy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.