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: LogLevelspecifies the log level of the message
format: Stringformat 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: boolused to catch unsent messages that accidentally get dropped
Implementations§
Source§impl Log
impl Log
Sourcepub fn new(level: LogLevel, format: &str) -> Self
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();Sourcepub fn arg(self, arg: impl Encoder + 'static) -> Self
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();Sourcepub fn opt_arg(self, arg: Option<impl Encoder + 'static>) -> Self
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();Sourcepub fn opt_arg_else(
self,
some_arg: Option<impl Encoder + 'static>,
none_arg: impl Encoder + 'static,
) -> Self
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();Sourcepub fn meta(self, key: &str, value: impl Encoder + 'static) -> Self
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();Sourcepub fn opt_meta(self, key: &str, value: Option<impl Encoder + 'static>) -> Self
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();Sourcepub fn send(self)
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();Sourcepub fn cancel(self)
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();