Log

Struct Log 

Source
pub struct Log {
    pub level: LogLevel,
    pub format: String,
    pub args: Vec<Rc<dyn Encoder>>,
    pub metadata: Vec<(String, Rc<dyn Encoder>)>,
    pub pending: bool,
}
Expand description

A structure to represent log messages.

Fields§

§level: LogLevel

specifies the log level of the message

§format: String

format string for the simple message, uses Erlang formatter syntax

§args: Vec<Rc<dyn Encoder>>

arguments for the format string

§metadata: Vec<(String, Rc<dyn Encoder>)>

metadata for the log message

§pending: bool

used to catch unsent messages that accidentally get dropped

Implementations§

Source§

impl Log

Source

pub fn new(level: LogLevel, format: &str) -> Self

Create a new Log builder.

Once created, a log message must be sent explicitly.

To prevent creating a log message but erroneously failing to send it, a panic is raised if a message is dropped without being sent.

If a message is legitimately created but not sent, use the cancel function.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, ~s!")
    .arg("world")
    .send();
Source

pub fn arg(self, arg: impl Encoder + 'static) -> Self

Builder-style method to put an argument into a log message.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, ~s!")
    .arg("world")
    .send();
Source

pub fn opt_arg(self, arg: Option<impl Encoder + 'static>) -> Self

Builder-style method to put an optional argument into a log message.

If the value is Some(arg), arg will be unwrapped and included in the log message. If the value is None, the key will not be included.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, ~s!")
    .opt_arg(Some("world"))
    .send();
Source

pub fn opt_arg_else( self, some_arg: Option<impl Encoder + 'static>, none_arg: impl Encoder + 'static, ) -> Self

Builder-style method to put an optional argument into a log message, or a default value if the argument is None.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, ~s!")
    .opt_arg_else(Some("world"), "unknown")
    .send();
Source

pub fn meta(self, key: &str, value: impl Encoder + 'static) -> Self

Builder-style method to put a key-value-pair into a log message.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, {}!")
    .arg("world")
    .meta("user_id", 123)
    .send();
Source

pub fn opt_meta(self, key: &str, value: Option<impl Encoder + 'static>) -> Self

Builder-style method to put an optional key-value-pair into a log message.

If the value is None, the key will not be included in the log message.

§Example
use rustler_logger::*;

let quota: Option<u64> = None;
let uid: Option<u64> = Some(1003);

let log = Log::new(LogLevel::Info, "Hello, {}!")
    .arg("world")
    .opt_meta("quota", quota)
    .opt_meta("uid", uid)
    .send();
Source

pub fn send(self)

Sends the constructed log message.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, {}!")
    .arg("world")
    .meta("user_id", 123)
    .send();
Source

pub fn cancel(self)

Cancel a log message that has not been sent yet.

If a message is constructed but not sent, it must be cancelled to prevent a panic. This panic occurs so that log messages won’t be constructed but then accidentally not sent.

§Example
use rustler_logger::*;

let log = Log::new(LogLevel::Info, "Hello, ~s!")
    .arg("world");

log.cancel();

Trait Implementations§

Source§

impl Clone for Log

Source§

fn clone(&self) -> Log

Returns a duplicate 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 Drop for Log

Source§

fn drop(&mut self)

Panic if a log message is dropped without being sent or cancelled.

Auto Trait Implementations§

§

impl Freeze for Log

§

impl !RefUnwindSafe for Log

§

impl !Send for Log

§

impl !Sync for Log

§

impl Unpin for Log

§

impl !UnwindSafe for Log

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.