comparison src/logging.rs @ 115:1e11a52b4665 default tip

Don't promise ordering for the log level.
author Paul Fisher <paul@pfish.zone>
date Sun, 29 Jun 2025 03:35:59 -0400
parents 178310336596
children
comparison
equal deleted inserted replaced
114:93d423b65555 115:1e11a52b4665
34 /// An entry to be added to the log. 34 /// An entry to be added to the log.
35 /// 35 ///
36 /// The levels are in descending order of importance and correspond roughly 36 /// The levels are in descending order of importance and correspond roughly
37 /// to the similarly-named levels in the `log` crate. 37 /// to the similarly-named levels in the `log` crate.
38 /// 38 ///
39 /// In all implementations, these are ordered such that `Error`, `Warning`, 39 /// Their values are ordered monotonically, either increasing or decreasing,
40 /// `Info`, and `Debug` are in ascending order. 40 /// depending upon the implementation.
41 #[derive(Debug, PartialEq, Ord, PartialOrd, Eq)] 41 #[derive(Debug, PartialEq, Eq)]
42 #[repr(i32)] 42 #[repr(i32)]
43 pub enum Level { 43 pub enum Level {
44 Error = levels::ERROR, 44 Error = levels::ERROR,
45 Warning = levels::WARN, 45 Warning = levels::WARN,
46 Info = levels::INFO, 46 Info = levels::INFO,
142 use super::*; 142 use super::*;
143 use regex::Regex; 143 use regex::Regex;
144 use std::cell::RefCell; 144 use std::cell::RefCell;
145 145
146 #[test] 146 #[test]
147 fn test_order() {
148 assert!(Level::Error < Level::Warning);
149 assert!(Level::Warning < Level::Info);
150 assert!(Level::Info < Level::Debug);
151 }
152
153 #[test]
154 fn test_logging() { 147 fn test_logging() {
155 struct Logger(RefCell<Vec<(Level, String)>>); 148 struct Logger(RefCell<Vec<(Level, String)>>);
156 149
157 impl Logger { 150 impl Logger {
158 fn log(&self, level: Level, text: &str) { 151 fn log(&self, level: Level, text: &str) {