logo

Struct log::Record

source · []
pub struct Record<'a> { /* private fields */ }
Expand description

The “payload” of a log message.

Use

Record structures are passed as parameters to the log method of the Log trait. Logger implementors manipulate these structures in order to display log messages. Records are automatically created by the log! macro and so are not seen by log users.

Note that the level() and target() accessors are equivalent to self.metadata().level() and self.metadata().target() respectively. These methods are provided as a convenience for users of this structure.

Example

The following example shows a simple logger that displays the level, module path, and message of any Record that is passed to it.

struct SimpleLogger;

impl log::Log for SimpleLogger {
   fn enabled(&self, metadata: &log::Metadata) -> bool {
       true
   }

   fn log(&self, record: &log::Record) {
       if !self.enabled(record.metadata()) {
           return;
       }

       println!("{}:{} -- {}",
                record.level(),
                record.target(),
                record.args());
   }
   fn flush(&self) {}
}

Implementations

Returns a new builder.

The message body.

Metadata about the log directive.

The verbosity level of the message.

The name of the target of the directive.

The module path of the message.

The module path of the message, if it is a 'static string.

The source file containing the message.

The module path of the message, if it is a 'static string.

The line containing the message.

The structured key-value pairs associated with the message.

Create a new RecordBuilder based on this record.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.