pub struct RuntimePattern(/* private fields */);
Available on crate feature
runtime-pattern
only.Expand description
Runtime pattern built via runtime_pattern!
macro.
§Basic Usage
use spdlog::info;
let formatter = PatternFormatter::new(runtime_pattern!("[{level}] {payload}{eol}")?);
info!(logger: doctest, "Interesting log message");
/* Output */ "[info] Interesting log message\n"
§With Custom Patterns
use std::fmt::Write;
use spdlog::{
formatter::{pattern, Pattern, PatternContext, PatternFormatter, runtime_pattern, RuntimePattern},
Record, StringBuf, info
};
#[derive(Default, Clone)]
struct MyPattern;
impl Pattern for MyPattern {
fn format(&self, record: &Record, dest: &mut StringBuf, _: &mut PatternContext) -> spdlog::Result<()> {
write!(dest, "My own pattern").map_err(spdlog::Error::FormatRecord)
}
}
let template = "[{level}] {payload} - {$mypat1} {$mypat2}{eol}";
fn pat() -> impl Pattern { pattern!("[{level_short}-{level}]") }
let formatter = PatternFormatter::new(
runtime_pattern!(
template,
{$mypat1} => MyPattern::default,
{$mypat2} => pat
)?
);
info!(logger: doctest, "Interesting log message");
/* Output */ "[info] Interesting log message - My own pattern [I-info]\n"
Trait Implementations§
Source§impl Clone for RuntimePattern
impl Clone for RuntimePattern
Source§fn clone(&self) -> RuntimePattern
fn clone(&self) -> RuntimePattern
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for RuntimePattern
impl !RefUnwindSafe for RuntimePattern
impl Send for RuntimePattern
impl Sync for RuntimePattern
impl Unpin for RuntimePattern
impl !UnwindSafe for RuntimePattern
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more