Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose logging levels #459

Merged
merged 4 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ impl Level {
pub fn as_str(&self) -> &'static str {
LOG_LEVEL_NAMES[*self as usize]
}

/// Iterate through all supported logging levels
///
/// The order of iteration is from more severe to less severe log messages
pub fn iter() -> impl Iterator<Item = Self> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth documenting something about the order of these fields. Using from_usize we’re effectively returning them in priority order.

What do you think?

(1..).flat_map(Self::from_usize)
}
}

/// An enum representing the available verbosity level filters of the logger.
Expand Down Expand Up @@ -722,6 +729,13 @@ impl LevelFilter {
pub fn as_str(&self) -> &'static str {
LOG_LEVEL_NAMES[*self as usize]
}

/// Iterate through all supported filtering levels
///
/// The order of iteration is from less to more verbose filtering
pub fn iter() -> impl Iterator<Item = Self> {
(0..).flat_map(Self::from_usize)
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
Expand Down