Skip to content

Enable custom levels and leave usize values for them #708

Description

@Pr0methean

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions