log icon indicating copy to clipboard operation
log copied to clipboard

Enable custom levels and leave usize values for them

Open Pr0methean opened this issue 2 months ago • 1 comments

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.

Pr0methean avatar Oct 22 '25 10:10 Pr0methean

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

tisonkun avatar Oct 29 '25 12:10 tisonkun