Skip to content

Custom log levels #636

Open
Open
@koraa

Description

Hi,

thank you all for writing a fantastic piece of software.

I am aware of #334.

My particular use case is having a log level "responsive" between warn and info.

rosenpass/rosenpass#326

Our goal is to be:

  • As silent as possible
  • Provide essentially a single line of output that we would otherwise mark log level info

Essentially be responsive without polluting logs.

Some ideas how to – cleanly – implement custom log levels:

  • Would it be possible to uniquely identify a particular log level through a constant variable? I.e. for instance ::log_level_critical::CRITICAL or log level ::rosenpass::util::log::level::RESPONSIVE which would be distinct from ::log_level_responsive::RESPONSIVE. This would allow clean reasoning about custom log levels across crates.
  • Would it be possible to specify constraints about how log level relate to each other?
    use log_custom_levels::{LogLevel, levels::INFO, Sort};
    
    // enum Sort {
    //     Lower,
    //     Equal,
    //     Higher,
    // }
    
    struct LogLevelResponsive {
        _phantom_private: ()
    }
    
    
    impl LogLevel for LogLevelResponsive {
        fn log_level_priority<Otr: LogLevelResponsive>(otr: Otr) -> Sort {
            use Sort::*;
            match INFO.log_level_priority(otr) {
                Lower  => Lower,
                Equal  => Higher,
                Higher => Higher,
            }
        }
    }
    
    const RESPONSIVE : LogLevelResponsive = LogLevelResponsive { _phantom_private: () };

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