Enable custom levels and leave usize values for them #708

Open
opened 2025-10-22 05:26:37 -05:00 by Pr0methean · 1 comment
Pr0methean commented 2025-10-22 05:26:37 -05:00 (Migrated from github.com)

https://docs.rs/log/latest/log/enum.Level.html gives the following numeric values of log levels:

#[repr(usize)]
pub enum Level {
    Error = 1,
    Warn = 2,
    Info = 3,
    Debug = 4,
    Trace = 5,
}

This makes it impossible to add custom levels between the predefined levels, and limits us to 1 custom level above Error -- and the latter, since it's the minimum value of usize, should really be reserved for "disable all logs". To both make custom levels easier to create and reduce the likelihood that users will need them, I propose to change the levels to the following:

#[repr(usize)]
pub enum Level {
    Off = 0,
    MAX = 1,
    Fatal = 500,
    Error = 1000,
    Warn = 2000,
    Notice = 2500,
    Info = 3000,
    Verbose = 3500,
    Debug = 4000,
    Trace = 5000,
    Fine = 6000,
    Hyperfine = 7000,
    Superhyperfine = 8000,
    MIN = usize::MAX - 1,
    All = usize::MAX,
}

with the default thresholds being:

  • For debug builds and non-prod configs, 0..=4500 to stderr and file;
  • For prod builds/configs, 0..=2250 to stderr and file, and 2251..=3250 to stdout and file, and 3251..=3750 to file only.
https://docs.rs/log/latest/log/enum.Level.html gives the following numeric values of log levels: ``` #[repr(usize)] pub enum Level { Error = 1, Warn = 2, Info = 3, Debug = 4, Trace = 5, } ``` This makes it impossible to add custom levels between the predefined levels, and limits us to 1 custom level above Error -- and the latter, since it's the minimum value of `usize`, should really be reserved for "disable all logs". To both make custom levels easier to create and reduce the likelihood that users will need them, I propose to change the levels to the following: ``` #[repr(usize)] pub enum Level { Off = 0, MAX = 1, Fatal = 500, Error = 1000, Warn = 2000, Notice = 2500, Info = 3000, Verbose = 3500, Debug = 4000, Trace = 5000, Fine = 6000, Hyperfine = 7000, Superhyperfine = 8000, MIN = usize::MAX - 1, All = usize::MAX, } ``` with the default thresholds being: - For debug builds and non-prod configs, 0..=4500 to stderr and file; - For prod builds/configs, 0..=2250 to stderr and file, and 2251..=3250 to stdout and file, and 3251..=3750 to file only.
tisonkun commented 2025-10-29 07:42:52 -05:00 (Migrated from github.com)

This is related to #334 and there is several discussion about the similar topic.

This is related to #334 and there is several discussion about the similar topic.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log#708
No description provided.