From a1f1748bfb79a57267fe0209320a7901f1ea97f1 Mon Sep 17 00:00:00 2001 From: Delma Date: Fri, 27 Aug 2021 14:32:49 +0300 Subject: [PATCH 1/4] Make log level names array public --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bbfb1ed31..edf001c40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -359,7 +359,12 @@ const INITIALIZED: usize = 2; static MAX_LOG_LEVEL_FILTER: AtomicUsize = AtomicUsize::new(0); -static LOG_LEVEL_NAMES: [&str; 6] = ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"]; +/// Array of supported filter levels for a logger. +/// +/// Values correspond to the variants of the [`LevelFilter`](enum.LevelFilter.html) enum. +/// +/// Can be used, for example, in help text shown to a user of an application. +pub static LOG_LEVEL_NAMES: [&str; 6] = ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"]; static SET_LOGGER_ERROR: &str = "attempted to set a logger after the logging system \ was already initialized"; From 0355d570ffd0129d5ce5e72748b2d59c96c888c5 Mon Sep 17 00:00:00 2001 From: Delma Date: Wed, 27 Oct 2021 17:59:29 +0300 Subject: [PATCH 2/4] Instead of making array public add iterator methods --- src/lib.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index edf001c40..777d3dce4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -359,12 +359,7 @@ const INITIALIZED: usize = 2; static MAX_LOG_LEVEL_FILTER: AtomicUsize = AtomicUsize::new(0); -/// Array of supported filter levels for a logger. -/// -/// Values correspond to the variants of the [`LevelFilter`](enum.LevelFilter.html) enum. -/// -/// Can be used, for example, in help text shown to a user of an application. -pub static LOG_LEVEL_NAMES: [&str; 6] = ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"]; +static LOG_LEVEL_NAMES: [&str; 6] = ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"]; static SET_LOGGER_ERROR: &str = "attempted to set a logger after the logging system \ was already initialized"; @@ -565,6 +560,11 @@ impl Level { pub fn as_str(&self) -> &'static str { LOG_LEVEL_NAMES[*self as usize] } + + /// Iterate through all supported logging levels + pub fn iter() -> impl Iterator { + (0..).flat_map(Self::from_usize) + } } /// An enum representing the available verbosity level filters of the logger. @@ -727,6 +727,11 @@ impl LevelFilter { pub fn as_str(&self) -> &'static str { LOG_LEVEL_NAMES[*self as usize] } + + /// Iterate through all supported filtering levels + pub fn iter() -> impl Iterator { + (0..).flat_map(Self::from_usize) + } } #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] From 299d3bcb5b438126c6356568bf4f2789003c37f6 Mon Sep 17 00:00:00 2001 From: Delma Date: Wed, 27 Oct 2021 18:02:07 +0300 Subject: [PATCH 3/4] Fixed a bug in Level::iter implementation --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 777d3dce4..d668c1a3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -563,7 +563,7 @@ impl Level { /// Iterate through all supported logging levels pub fn iter() -> impl Iterator { - (0..).flat_map(Self::from_usize) + (1..).flat_map(Self::from_usize) } } From 05532fabfd3eadce4d640a364f130d729abc2b64 Mon Sep 17 00:00:00 2001 From: Delma Date: Fri, 5 Nov 2021 18:51:42 +0200 Subject: [PATCH 4/4] Added documentation on the order of iteration --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d668c1a3a..b4df51259 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -562,6 +562,8 @@ impl Level { } /// Iterate through all supported logging levels + /// + /// The order of iteration is from more severe to less severe log messages pub fn iter() -> impl Iterator { (1..).flat_map(Self::from_usize) } @@ -729,6 +731,8 @@ impl LevelFilter { } /// Iterate through all supported filtering levels + /// + /// The order of iteration is from less to more verbose filtering pub fn iter() -> impl Iterator { (0..).flat_map(Self::from_usize) }