Expose logging levels #459
No reviewers
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log!459
Loading…
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I am using
FromStrimplementation ofLevelFilterto parse logging level given by user via command line flag. In case user gives invalid logging level I want to print list of allowed values. Currently I have to replicateLOG_LEVEL_NAMESarray in my code and remember to keep it in sync (It is probably unlikely it changes that much though).One question I have is that is there a reason it is
staticinstead ofconst?Hey @WaDelma 👋
There probably isn't a great reason for this to be
staticrather thanconst. Rather than make the array public though I think a static method onLevelthat returns someimpl Iterator<Item = Level>might be better:That way in your code you could call something like:
The reason I think we should avoid making the array public is that it would be a breaking change to add any more levels (as unlikely as that is) because the type would change from
[&'static str; 6]to[&'static str; 7].Makes sense. I added such static methods for both
LevelandLevelFilter,@ -563,0 +564,4 @@/// Iterate through all supported logging levels////// The order of iteration is from more severe to less severe log messagespub fn iter() -> impl Iterator<Item = Self> {It might be worth documenting something about the order of these fields. Using
from_usizewe’re effectively returning them in priority order.What do you think?
Thanks for working on this @WaDelma!