slog_stream/
format.rs

1
2/// Formats `Record`-s into IO
3pub trait Format: Send + Sync + Sized {
4    /// Format one logging record and write into `io`
5    fn format(&self,
6              io: &mut io::Write,
7              info: &Record,
8              logger_values: &OwnedKeyValueList)
9              -> io::Result<()>;
10}
11
12/// Formatted stream decorator
13///
14/// Some `Format`s for which it make sense can use this to parametrize
15/// themselves on the exact behavior of formatting parts of the output. This
16/// can be used eg. to use color when displaying logger records on the terminal.
17pub trait Decorator: Send + Sync + Sized {
18    /// Per-record decorator
19    type RecordDecorator: RecordDecorator;
20
21    /// Get a `RecordDecorator` for a given `record`
22    fn decorate(&self, record: &Record) -> Self::RecordDecorator;
23}
24
25/// Per-record decorator
26// TODO 2.0: Make everything take `&mut self`.
27// TODO 2.0: Make everything take `f: &FnOnce`
28pub trait RecordDecorator {
29    /// Format a field
30    fn fmt_msg(&self, io: &mut io::Write, f: &Fn(&mut io::Write) -> io::Result<()>) -> io::Result<()> {
31        f(io)
32    }
33    /// Format a key
34    fn fmt_key(&self, io: &mut io::Write, f: &Fn(&mut io::Write) -> io::Result<()>) -> io::Result<()> {
35        f(io)
36    }
37    /// Format a separator
38    fn fmt_separator(&self, io: &mut io::Write, f: &Fn(&mut io::Write) -> io::Result<()>) -> io::Result<()> {
39        f(io)
40    }
41    /// Format a value
42    fn fmt_value(&self, io: &mut io::Write, f: &Fn(&mut io::Write) -> io::Result<()>) -> io::Result<()> {
43        f(io)
44    }
45    /// Format a timestamp
46    fn fmt_timestamp(&self, io: &mut io::Write, f : &Fn(&mut io::Write) -> io::Result<()>) -> io::Result<()> {
47        f(io)
48    }
49    /// Format a level
50    fn fmt_level(&self, io: &mut io::Write, f: &Fn(&mut io::Write) -> io::Result<()>) -> io::Result<()> {
51        f(io)
52    }
53}