log

Struct Logger

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

source

pub fn new(name: &str) -> Self

Creates a new instance of a Logger.

source

pub fn sink<S: Sink<MD> + 'static>(&mut self, sink: S)

Adds a Sink to this Logger.

Messages that get logged to the Logger will delegate logging down to the specified Sink object(s).

§Parameters
  • sink - the Sink to write to.
source

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
source§

impl<MD> Logger<MD>

source

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 level
  • args - the formatting arguments
  • meta - additional meta data to optionally provide to the logger.
source

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 arguments
  • meta - additional meta data to optionally provide to the logger.
source

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 arguments
  • meta - additional meta data to optionally provide to the logger.
source

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 arguments
  • meta - additional meta data to optionally provide to the logger.
source

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 arguments
  • meta - additional meta data to optionally provide to the logger.
source

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 arguments
  • meta - additional meta data to optionally provide to the logger.

Auto Trait Implementations§

§

impl<MD> Freeze for Logger<MD>

§

impl<MD = NoMeta> !RefUnwindSafe for Logger<MD>

§

impl<MD = NoMeta> !Send for Logger<MD>

§

impl<MD = NoMeta> !Sync for Logger<MD>

§

impl<MD> Unpin for Logger<MD>

§

impl<MD = NoMeta> !UnwindSafe for Logger<MD>

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