Skip to content

Consider using "WARNING" instead of "WARN" for the log level. #2964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
josecelano opened this issue May 8, 2024 · 1 comment
Closed

Consider using "WARNING" instead of "WARN" for the log level. #2964

josecelano opened this issue May 8, 2024 · 1 comment

Comments

@josecelano
Copy link

josecelano commented May 8, 2024

Feature Request

I was setting up Datadog for a project I'm working on, and I realized log lines containing "WARN" were categorised as "INFO".

Datadog uses the severity levels described here:

https://en.wikipedia.org/wiki/Syslog#Severity_level

"WARN" is deprecated in favour of "WARNING." It's not a problem because you can remap the status. However, I've seen some libraries also encourage using the whole word "WARNING."

I guess that change would be a breaking change even if you only change the Display implementation:

impl fmt::Display for Level {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match *self {
            Level::TRACE => f.pad("TRACE"),
            Level::DEBUG => f.pad("DEBUG"),
            Level::INFO => f.pad("INFO"),
            Level::WARN => f.pad("WARN"),
            Level::ERROR => f.pad("ERROR"),
        }
    }
}

Crates

tracing-core

Motivation

It potentially improves the user experience when parsing the logs generated by the tracing crate by providing a smooth integration with other services that parse logs.

I've asked ChatGPT which languages/packages are recommending this change:

The deprecation of "WARN" in favor of "WARNING" is typically seen in logging frameworks and libraries rather than in programming languages themselves. Some examples include:

  1. Java Logging (java.util.logging): In Java's built-in logging framework, using "WARN" has been discouraged in favor of "WARNING."

  2. Log4j: Log4j, a popular logging library for Java, has historically used "WARN" as a logging level. However, it's recommended to use "WARN" as an alias for "WARNING" for consistency.

  3. Python logging module: Python's logging module uses "WARNING" instead of "WARN" to represent log levels indicating potential issues or warnings.

  4. Syslog: As you mentioned, in the syslog standard, "WARN" has been deprecated in favor of "WARNING."

In general, this deprecation is part of a broader trend towards clearer and more consistent logging practices, making log messages easier to understand and analyze across different systems and programming languages.

Proposal

Allow users to remap/overwrite these keywords. And keep the current ones as defaults.

Alternatives

I guess you could just change it in the next big release if there is consensus. To be honest, I don't see "WARN" as a big problem. Datadog is just one provider, and others may keep using it.

@davidbarsky
Copy link
Member

We're going to stick with WARN in order to be closer to the log crate, I'm afraid: https://docs.rs/log/latest/log/enum.Level.html.

If you're running into issue with DataDog, I'd consider defining your own formatters for tracing_subscriber::fmt (which I assume you're doing) similar to what I did in tracing-glog: https://github.com/davidbarsky/tracing-glog/blob/main/src/format.rs#L15

@davidbarsky davidbarsky closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants