7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | use std::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | fmt, fs, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | io::{self, BufRead, Write}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | path, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | str::FromStr, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | time::Duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | use chrono::{DateTime, FixedOffset}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | use regex::RegexBuilder; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | use crate::Result; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | const OUTPUT_TEMPLATE: &str = include_str!("timer.template.html"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result<()> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | let find_timer = RegexBuilder::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | r#" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | # Let's start. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | ^ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | # Datetime of the log line. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | (?<datetime>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | # Log level. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | \s+(?<level>\S+) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | # Target. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | \s(?<target>matrix_[\w_]+(::[\w_]+)*): |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | # The timer message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | \s(?<message>(Timer\s)?_.*?_) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | \sfinished\sin |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | # The timer duration. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | \s(?<duration>\d(\.\d+)?.*s) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | # The source file and line. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | \s\|\scrates/ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | (?<source_file>[^:]+) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | :(?<source_line>\d+) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | "#, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | .ignore_whitespace(true) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | .build() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | .expect("Failed to build the `find_timer` regex"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | let log_file = fs::File::open(&log_path)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | let mut output_file = io::BufWriter::new(fs::File::create(&output_path)?); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | let reader = io::BufReader::new(log_file); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | let mut number_of_analysed_lines = 0; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | let mut number_of_matched_lines = 0; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | let mut timers = Vec::<Timer>::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | for line in reader.lines().enumerate().map(|(nth, line)| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | line.unwrap_or_else(|error| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | panic!("Failed to read line #{nth}\n{error}"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | }) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | number_of_analysed_lines += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | if let Some(captures) = find_timer.captures(&line) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | number_of_matched_lines += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | let date_time = DateTime::parse_from_rfc3339( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | captures.name("datetime").expect("Failed to capture `datetime`").as_str(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | .expect("Failed to parse `datetime`"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | let level = captures |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | .name("level") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | .expect("Failed to capture `level`") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | .as_str() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | .parse() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | .expect("Failed to parse the `level`"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | let target = captures.name("target").expect("Failed to capture `target`").as_str(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | let message = captures.name("message").expect("Failed to capture `message`").as_str(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | let duration_as_str = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | captures.name("duration").expect("Failed to capture `duration`").as_str(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | let duration = { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | let duration = duration_as_str; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | // According to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | // https://github.com/rust-lang/rust/blob/0028f344ce9f64766259577c998a1959ca1f6a0b/library/core/src/time.rs#L1488-L15 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | // 10, there is 4 possible suffixes. Let's get through them. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | let pivot = duration.floor_char_boundary(duration.len().saturating_sub(2)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | Duration::from_nanos(match &duration[pivot..] { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | // nanoseconds |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | "ns" => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | let duration: f64 = duration[..pivot].parse().unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 94 | duration.abs().round() as u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 95 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 96 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | "µs" => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | let duration: f64 = duration[..pivot].parse().unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | (duration * 1_000.0).abs().round() as u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | "ms" => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | let duration: f64 = duration[..pivot].parse().unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | (duration * 1_000_000.0).abs().round() as u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | // seconds! |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | _ => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | let duration: f64 = duration[..pivot.saturating_add(1)].parse().unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | (duration * 1_000_000_000.0).abs().round() as u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 116 | let source_file = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 117 | captures.name("source_file").expect("Failed to capture `source_file`").as_str(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 118 | let source_line = captures |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 119 | .name("source_line") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 120 | .expect("Failed to capture `source_line`") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 121 | .as_str() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 122 | .parse() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 123 | .expect("Failed to parse the `source_line`"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 124 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 125 | // Ensure we have parsed the duration correctly (in case Rust stdlib changes |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 126 | // something). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 127 | assert_eq!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 128 | duration_as_str, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 129 | format!("{duration:?}"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 130 | "Failed to parse the `duration` as expected" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 131 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 132 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 133 | timers.push(Timer { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 134 | date_time, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 135 | level, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 136 | target: target.to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 137 | message: message[1..message.len() - 1].to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 138 | duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 139 | source_file: source_file.to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 140 | source_line, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 141 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 142 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 143 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 144 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 145 | timers.sort_by(|a, b| a.duration.cmp(&b.duration).reverse()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 146 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 147 | fn render(timers: Vec<Timer>, buffer: &mut io::BufWriter<fs::File>) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 148 | for Timer { duration, level, message, target, source_file, source_line, date_time } in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 149 | timers |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 150 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 151 | writeln!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 152 | buffer, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 153 | "<tr>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 154 | <td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 155 | <div class=\"span\" style=\"--duration: {duration}\"><span>{duration_label:?}</span></div>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 156 | </td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 157 | <td>{message}</td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 158 | <td><span class=\"{level_class}\">{level}</span></td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 159 | <td><code>{target}</code></td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 160 | <td><code>{source_file}:{source_line}</code></td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 161 | <td><time datetime=\"{date_time}\">{time}</time></td>\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 162 | </tr>\n", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 163 | level_class = level.css(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 164 | duration = duration.as_nanos(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 165 | duration_label = duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 166 | date_time = date_time.format("%+"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 167 | time = date_time.format("%H:%M:%S%.3f"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 168 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 169 | .unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 170 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 171 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 172 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 173 | let output = OUTPUT_TEMPLATE.replace("{log_file}", &log_path.to_string_lossy()).replace( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 174 | "{longest-duration}", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 175 | &timers.first().map(|timer| timer.duration.as_nanos()).unwrap_or(0).to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 176 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 177 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 178 | output_file.write_all(output.as_bytes()).expect("Failed to write the output"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 179 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 180 | render(timers, &mut output_file); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 181 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 182 | output_file |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 183 | .write_all( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 184 | " </tbody> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 185 | </table> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 186 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 187 | </main> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 188 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 189 | </body> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 190 | </html>" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 191 | .as_bytes(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 192 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 193 | .expect("Failed to write the output"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 194 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 195 | println!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 196 | "\nNumber of analysed log lines: {number_of_analysed_lines}\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 197 | Number of matched lines: {number_of_matched_lines}\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 198 | Output file: {output_path:?}\n\ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 199 | Done!" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 200 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 201 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 202 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 203 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 204 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 205 | #[derive(Debug)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 206 | struct Timer { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 207 | date_time: DateTime<FixedOffset>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 208 | level: Level, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 209 | target: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 210 | message: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 211 | duration: Duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 212 | source_file: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 213 | source_line: usize, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 214 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 215 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 216 | #[derive(Debug, Eq, PartialEq, Ord, PartialOrd)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 217 | enum Level { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 218 | Error, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 219 | Warn, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 220 | Info, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 221 | Debug, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 222 | Trace, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 223 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 224 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 225 | impl Level { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 226 | fn css(&self) -> &str { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 227 | match self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 228 | Self::Error => "error", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 229 | Self::Warn => "warn", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 230 | Self::Info => "info", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 231 | Self::Debug => "debug", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 232 | Self::Trace => "trace", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 233 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 234 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 235 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 236 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 237 | impl FromStr for Level { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 238 | type Err = (); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 239 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 240 | fn from_str(str: &str) -> Result<Self, Self::Err> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 241 | Ok(match str { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 242 | "ERROR" => Self::Error, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 243 | "WARN" => Self::Warn, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 244 | "INFO" => Self::Info, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 245 | "DEBUG" => Self::Debug, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 246 | "TRACE" => Self::Trace, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 247 | _ => return Err(()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 248 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 249 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 250 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 251 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 252 | impl fmt::Display for Level { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 253 | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 254 | write!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 255 | formatter, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 256 | "{}", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 257 | match self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 258 | Self::Error => "ERROR", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 259 | Self::Warn => "WARNING", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 260 | Self::Info => "INFO", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 261 | Self::Debug => "DEBUG", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 262 | Self::Trace => "TRACE", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 263 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 264 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 265 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 266 | } |