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>
impl<F: Flag> Log<F>
sourcepub fn new() -> Self
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.
sourcepub fn fork(&self, attrs: impl Fn(&mut HashMap<&'static str, String>)) -> Self
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, ...));
.
sourcepub fn with_flags(self, flags: &[F]) -> Self
pub fn with_flags(self, flags: &[F]) -> Self
Initialize or replace flags and return a new Log instance.
sourcepub fn log(&self, flag: F, message: impl ToString)
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.
sourcepub fn log_with(
&self,
flag: F,
message: impl ToString,
attrs: impl Fn(&mut HashMap<&'static str, String>)
)
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.
pub fn log_err(&self, flag: F, e: Error)
sourcepub fn err(&self, message: impl ToString) -> Error
pub fn err(&self, message: impl ToString) -> Error
Create a new error including the attributes in this logging context.
sourcepub fn err_with(
&self,
message: impl ToString,
attrs: impl Fn(&mut HashMap<&'static str, String>)
) -> Error
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.