pub trait Pattern: Send + Sync {
fn format(
&self,
record: &Record<'_>,
dest: &mut StringBuf,
ctx: &mut PatternContext
) -> Result<()>;
}
Expand description
A pattern.
A pattern is like a formatter, except that multiple patterns can be combined
in various ways to create a new pattern. The PatternFormatter
struct
provides a Formatter
that formats log records according to a given
pattern.
Built-in Patterns
spdlog
provides a rich set of built-in patterns. See the pattern
macro.
Custom Patterns
There are 2 approaches to create your own pattern:
- Define a new type and implements this trait;
- Use the
pattern
macro to create a pattern from a template string.
Required Methods
sourcefn format(
&self,
record: &Record<'_>,
dest: &mut StringBuf,
ctx: &mut PatternContext
) -> Result<()>
fn format(
&self,
record: &Record<'_>,
dest: &mut StringBuf,
ctx: &mut PatternContext
) -> Result<()>
Format this pattern against the given log record and write the formatted message into the output buffer.
For implementors: the ctx
parameter is reserved for future use.
For now, please ignore it.