pub struct PatternFormatter<P> { /* private fields */ }Expand description
Formats logs according to a specified pattern.
Implementations§
Source§impl<P> PatternFormatter<P>where
P: Pattern,
impl<P> PatternFormatter<P>where
P: Pattern,
Sourcepub fn new(pattern: P) -> Self
pub fn new(pattern: P) -> Self
Creates a new PatternFormatter object with the given pattern.
Currently users can only create a pattern object by using:
- Macro
pattern!to build a pattern with a literal template string at compile-time. - Macro
runtime_pattern!to build a pattern at runtime.
Examples found in repository?
examples/04-format.rs (lines 21-23)
13fn use_pattern_formatter() {
14 use spdlog::{
15 formatter::{pattern, PatternFormatter},
16 prelude::*,
17 };
18
19 // Building a pattern formatter with a pattern.
20 // The `pattern!` macro will parse the template string at compile-time.
21 let new_formatter = Box::new(PatternFormatter::new(pattern!(
22 "{datetime} - {^{level}} - {payload}{eol}"
23 )));
24
25 // Setting the new formatter for each sink of the default logger.
26 for sink in spdlog::default_logger().sinks() {
27 sink.set_formatter(new_formatter.clone())
28 }
29
30 info!("format by `PatternFormatter`");
31}Trait Implementations§
Source§impl<P: Clone> Clone for PatternFormatter<P>
impl<P: Clone> Clone for PatternFormatter<P>
Source§fn clone(&self) -> PatternFormatter<P>
fn clone(&self) -> PatternFormatter<P>
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<P> Freeze for PatternFormatter<P>where
P: Freeze,
impl<P> RefUnwindSafe for PatternFormatter<P>where
P: RefUnwindSafe,
impl<P> Send for PatternFormatter<P>where
P: Send,
impl<P> Sync for PatternFormatter<P>where
P: Sync,
impl<P> Unpin for PatternFormatter<P>where
P: Unpin,
impl<P> UnwindSafe for PatternFormatter<P>where
P: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)