Struct loga::types::Log

source ·
pub struct Log<F: Flag> { /* private fields */ }
Expand description

A store of context with methods for logging and creating errors expressing that context.

Unnecessary detail: This is called “Log” because this object will take the place of a log or logger in most code and thus is unlikely to overlap. Naming it “Context” or similar would possibly conflict with other domains’ “context” objects. The two hardest things when programming, as they say - no need to make things harder.

Implementations§

source§

impl<F: Flag> Log<F>

source

pub fn new() -> Self

Create a new logger (defaults to Debug level, change with with_level). You may want to alias this with your flag type of choice.

source

pub fn fork(&self, attrs: impl Fn(&mut HashMap<&'static str, String>)) -> Self

Create a new Log that inherits attributes from the base logging context. Use like let new_log = log.fork(ea!(newkey = newvalue, ...));.

source

pub fn with_flags(self, flags: &[F]) -> Self

Initialize or replace flags and return a new Log instance.

source

pub fn log(&self, flag: F, message: impl ToString)

Log a message. The message will only be rendered and output if any of the specified flags are set.

source

pub fn log_with( &self, flag: F, message: impl ToString, attrs: impl Fn(&mut HashMap<&'static str, String>) )

Log a message. The attributes will only be evaluated and the message will only be rendered and output if any of the specified flags are set.

source

pub fn log_err(&self, flag: F, e: Error)

source

pub fn err(&self, message: impl ToString) -> Error

Create a new error including the attributes in this logging context.

source

pub fn err_with( &self, message: impl ToString, attrs: impl Fn(&mut HashMap<&'static str, String>) ) -> Error

Create a new error including the attributes in this logging context and merging additional attributes.

source

pub fn agg_err(&self, message: impl ToString, errs: Vec<Error>) -> Error

Create an error from multiple errors, attaching the Log’s attributes.

source

pub fn agg_err_with( &self, message: impl ToString, errs: Vec<Error>, attrs: impl Fn(&mut HashMap<&'static str, String>) ) -> Error

Create an error from multiple errors, attaching the Log’s attributes and additional attributes.

Trait Implementations§

source§

impl<F: Clone + Flag> Clone for Log<F>

source§

fn clone(&self) -> Log<F>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<F: Flag> Default for Log<F>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for Log<F>
where F: RefUnwindSafe,

§

impl<F> Send for Log<F>
where F: Send,

§

impl<F> Sync for Log<F>
where F: Sync,

§

impl<F> Unpin for Log<F>
where F: Unpin,

§

impl<F> UnwindSafe for Log<F>
where F: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.