pub struct Logger<MD = NoMeta> { /* private fields */ }Expand description
An instance of a Logger in this crate.
Logger objects may optionally emit meta data, which is free-form data
that will be passed down to the underlying Sink instances. It is up for
users of the logger to implement Sink with a custom meta-data if there
is an intent to handle this in some way.
Actual meta data is always optional for the user to provide. The idiomatic way to provide this metadata is through one of the logging macros:
Implementations§
source§impl<MD> Logger<MD>
impl<MD> Logger<MD>
sourcepub fn sink_with_filter<S: Sink<MD> + 'static>(
&mut self,
sink: S,
filter: SeverityFilter,
)
pub fn sink_with_filter<S: Sink<MD> + 'static>( &mut self, sink: S, filter: SeverityFilter, )
Adds a Sink to this Logger that will only be written to if the
filter allows it.
§Parameters
sink- theSinkto write to.filter- theSeverityFilterto enable writing.
source§impl<MD> Logger<MD>
impl<MD> Logger<MD>
sourcepub fn log(&mut self, severity: Severity, args: Arguments<'_>, meta: &Meta<MD>)
pub fn log(&mut self, severity: Severity, args: Arguments<'_>, meta: &Meta<MD>)
Logs a message of formatted args at the given severity.
§Parameters
severity- the log severity levelargs- the formatting argumentsmeta- additional meta data to optionally provide to the logger.
sourcepub fn debug(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
pub fn debug(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
Logs a message of formatted args at debug severity
This is a convenience function that just wraps Logger::log with a
specified Debug log severity
§Examples
Basic use:
log::debug!(logger, "Hello {}!", "world");Direct use:
// This is a less-standard example; but it allows for this to be used
// from within other macro definitions.
logger.debug(std::format_args!("hello {}", "world"), &log::metadata!())§Parameters
args- the formatting argumentsmeta- additional meta data to optionally provide to the logger.
sourcepub fn info(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
pub fn info(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
Logs a message of formatted args at info severity
This is a convenience function that just wraps Logger::log with a
specified Info log severity
§Examples
Basic use:
log::info!(logger, "Hello {}!", "world");Direct use:
// This is a less-standard example; but it allows for this to be used
// from within other macro definitions.
logger.info(std::format_args!("hello {}", "world"), &log::metadata!())§Parameters
args- the formatting argumentsmeta- additional meta data to optionally provide to the logger.
sourcepub fn warning(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
pub fn warning(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
Logs a message of formatted args at warning severity
This is a convenience function that just wraps Logger::log with a
specified Warning log severity
§Examples
Basic use:
log::warning!(logger, "Hello {}!", "world");Direct use:
// This is a less-standard example; but it allows for this to be used
// from within other macro definitions.
logger.warning(std::format_args!("hello {}", "world"), &log::metadata!())§Parameters
args- the formatting argumentsmeta- additional meta data to optionally provide to the logger.
sourcepub fn error(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
pub fn error(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
Logs a message of formatted args at error severity
This is a convenience function that just wraps Logger::log with a
specified Error log severity
§Examples
Basic use:
log::error!(logger, "Hello {}!", "world");Direct use:
// This is a less-standard example; but it allows for this to be used
// from within other macro definitions.
logger.error(std::format_args!("hello {}", "world"), &log::metadata!())§Parameters
args- the formatting argumentsmeta- additional meta data to optionally provide to the logger.
sourcepub fn critical(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
pub fn critical(&mut self, args: Arguments<'_>, meta: &Meta<MD>)
Logs a message of formatted args at critical severity
This is a convenience function that just wraps Logger::log with a
specified Critical log severity
§Examples
Basic use:
log::critical!(logger, "Hello {}!", "world");Direct use:
// This is a less-standard example; but it allows for this to be used
// from within other macro definitions.
logger.critical(std::format_args!("hello {}", "world"), &log::metadata!())§Parameters
args- the formatting argumentsmeta- additional meta data to optionally provide to the logger.