|
41 | 41 | //! a formatter does not accept any argument. |
42 | 42 | //! |
43 | 43 | //! * `d`, `date` - The current time. By default, the ISO 8601 format is used. |
44 | | -//! A custom format may be provided in the syntax accepted by `chrono`. |
45 | | -//! The timezone defaults to local, but can be specified explicitly by |
46 | | -//! passing a second argument of `utc` for UTC or `local` for local time. |
47 | | -//! * `{d}` - `2016-03-20T14:22:20.644420340-08:00` |
48 | | -//! * `{d(%Y-%m-%d %H:%M:%S)}` - `2016-03-20 14:22:20` |
49 | | -//! * `{d(%Y-%m-%d %H:%M:%S %Z)(utc)}` - `2016-03-20 22:22:20 UTC` |
| 44 | +//! A custom format may be provided in the syntax accepted by `chrono`. |
| 45 | +//! The timezone defaults to local, but can be specified explicitly by |
| 46 | +//! passing a second argument of `utc` for UTC or `local` for local time. |
| 47 | +//! * `{d}` - `2016-03-20T14:22:20.644420340-08:00` |
| 48 | +//! * `{d(%Y-%m-%d %H:%M:%S)}` - `2016-03-20 14:22:20` |
| 49 | +//! * `{d(%Y-%m-%d %H:%M:%S %Z)(utc)}` - `2016-03-20 22:22:20 UTC` |
50 | 50 | //! * `f`, `file` - The source file that the log message came from, or `???` if |
51 | | -//! not provided. |
| 51 | +//! not provided. |
52 | 52 | //! * `h`, `highlight` - Styles its argument according to the log level. The |
53 | | -//! style is intense red for errors, red for warnings, blue for info, and |
54 | | -//! the default style for all other levels. |
55 | | -//! * `{h(the level is {l})}` - |
56 | | -//! <code style="color: red; font-weight: bold">the level is ERROR</code> |
| 53 | +//! style is intense red for errors, red for warnings, blue for info, and |
| 54 | +//! the default style for all other levels. |
| 55 | +//! * `{h(the level is {l})}` - |
| 56 | +//! <code style="color: red; font-weight: bold">the level is ERROR</code> |
57 | 57 | //! * `D`, `debug` - Outputs its arguments ONLY in debug build. |
58 | 58 | //! * `R`, `release` - Outputs its arguments ONLY in release build. |
59 | 59 | //! * `l`, `level` - The log level. |
60 | 60 | //! * `L`, `line` - The line that the log message came from, or `???` if not |
61 | | -//! provided. |
| 61 | +//! provided. |
62 | 62 | //! * `m`, `message` - The log message. |
63 | 63 | //! * `M`, `module` - The module that the log message came from, or `???` if not |
64 | | -//! provided. |
| 64 | +//! provided. |
65 | 65 | //! * `P`, `pid` - The current process id. |
66 | 66 | //! * `i`, `tid` - The current system-wide unique thread ID. |
67 | 67 | //! * `n` - A platform-specific newline. |
68 | 68 | //! * `t`, `target` - The target of the log message. |
69 | 69 | //! * `T`, `thread` - The name of the current thread. |
70 | 70 | //! * `I`, `thread_id` - The pthread ID of the current thread. |
71 | 71 | //! * `X`, `mdc` - A value from the [MDC][MDC]. The first argument specifies |
72 | | -//! the key, and the second argument specifies the default value if the |
73 | | -//! key is not present in the MDC. The second argument is optional, and |
74 | | -//! defaults to the empty string. |
| 72 | +//! the key, and the second argument specifies the default value if the |
| 73 | +//! key is not present in the MDC. The second argument is optional, and |
| 74 | +//! defaults to the empty string. |
75 | 75 | //! * `{X(user_id)}` - `123e4567-e89b-12d3-a456-426655440000` |
76 | 76 | //! * `{X(nonexistent_key)(no mapping)}` - `no mapping` |
77 | 77 | //! * `K`, `key_value` - A value from a [log::kv][log_kv] structured logging |
78 | | -//! record attributes. The first argument specifies the key, and the second |
79 | | -//! argument specifies the default value if the key is not present in the |
80 | | -//! log record's attributes. The second argument is optional, and defaults |
81 | | -//! to the empty string. This formatter requires the `log_kv` feature to be |
82 | | -//! enabled. |
83 | | -//! * `{K(user_id)}` - `123e4567-e89b-12d3-a456-426655440000` |
84 | | -//! * `{K(nonexistent_key)(no mapping)}` - `no mapping` |
| 78 | +//! record attributes. The first argument specifies the key, and the second |
| 79 | +//! argument specifies the default value if the key is not present in the |
| 80 | +//! log record's attributes. The second argument is optional, and defaults |
| 81 | +//! to the empty string. This formatter requires the `log_kv` feature to be |
| 82 | +//! enabled. |
| 83 | +//! * `{K(user_id)}` - `123e4567-e89b-12d3-a456-426655440000` |
| 84 | +//! * `{K(nonexistent_key)(no mapping)}` - `no mapping` |
85 | 85 | //! * An "unnamed" formatter simply formats its argument, applying the format |
86 | | -//! specification. |
87 | | -//! * `{({l} {m})}` - `INFO hello` |
| 86 | +//! specification. |
| 87 | +//! * `{({l} {m})}` - `INFO hello` |
88 | 88 | //! |
89 | 89 | //! # Format Specification |
90 | 90 | //! |
|
101 | 101 | //! |
102 | 102 | //! * `<` - Left align by appending the fill character to the formatter output |
103 | 103 | //! * `>` - Right align by prepending the fill character to the formatter |
104 | | -//! output. |
| 104 | +//! output. |
105 | 105 | //! |
106 | 106 | //! ## Width |
107 | 107 | //! |
@@ -183,7 +183,7 @@ enum Chunk { |
183 | 183 | } |
184 | 184 |
|
185 | 185 | impl Chunk { |
186 | | - fn encode(&self, w: &mut dyn encode::Write, record: &Record<'_> ) -> io::Result<()> { |
| 186 | + fn encode(&self, w: &mut dyn encode::Write, record: &Record<'_>) -> io::Result<()> { |
187 | 187 | match *self { |
188 | 188 | Chunk::Text(ref s) => w.write_all(s.as_bytes()), |
189 | 189 | Chunk::Formatted { |
@@ -546,7 +546,7 @@ fn no_args(arg: &[Vec<Piece<'_>>], params: Parameters, chunk: FormattedChunk) -> |
546 | 546 | } |
547 | 547 | } |
548 | 548 |
|
549 | | -fn kv_parsing<'a>(formatter: &'a Formatter<'_> ) -> Result<(String, String), &'a str> { |
| 549 | +fn kv_parsing<'a>(formatter: &'a Formatter<'_>) -> Result<(String, String), &'a str> { |
550 | 550 | if formatter.args.len() > 2 { |
551 | 551 | return Err("expected at most two arguments"); |
552 | 552 | } |
@@ -613,7 +613,7 @@ enum FormattedChunk { |
613 | 613 | } |
614 | 614 |
|
615 | 615 | impl FormattedChunk { |
616 | | - fn encode(&self, w: &mut dyn encode::Write, record: &Record<'_> ) -> io::Result<()> { |
| 616 | + fn encode(&self, w: &mut dyn encode::Write, record: &Record<'_>) -> io::Result<()> { |
617 | 617 | match *self { |
618 | 618 | FormattedChunk::Time(ref fmt, Timezone::Utc) => write!(w, "{}", Utc::now().format(fmt)), |
619 | 619 | FormattedChunk::Time(ref fmt, Timezone::Local) => { |
@@ -718,7 +718,7 @@ impl Default for PatternEncoder { |
718 | 718 | } |
719 | 719 |
|
720 | 720 | impl Encode for PatternEncoder { |
721 | | - fn encode(&self, w: &mut dyn encode::Write, record: &Record<'_> ) -> anyhow::Result<()> { |
| 721 | + fn encode(&self, w: &mut dyn encode::Write, record: &Record<'_>) -> anyhow::Result<()> { |
722 | 722 | for chunk in &self.chunks { |
723 | 723 | chunk.encode(w, record)?; |
724 | 724 | } |
@@ -790,10 +790,10 @@ mod tests { |
790 | 790 | use crate::encode::Encode; |
791 | 791 |
|
792 | 792 | fn error_free(encoder: &PatternEncoder) -> bool { |
793 | | - encoder.chunks.iter().all(|c| match *c { |
794 | | - Chunk::Error(_) => false, |
795 | | - _ => true, |
796 | | - }) |
| 793 | + encoder |
| 794 | + .chunks |
| 795 | + .iter() |
| 796 | + .all(|c| !matches!(*c, Chunk::Error(_))) |
797 | 797 | } |
798 | 798 |
|
799 | 799 | #[test] |
|
0 commit comments