-
Notifications
You must be signed in to change notification settings - Fork 721
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
[Draft] Add support for additional log levels #3072
Comments
I think this relates to this issue and comment. Personally, I'm not convinced the additional levels are necessary, but focusing purely on the technical side: I think the implementation with
An alternative would be to add this in a new breaking version. There's been talks of a breaking version for a few years and I wouldn't expect it anytime soon so if you want this early, that might not be viable. But I think that's the most likely way to get this into What I think you could do right now is have a separate field like |
In this case, I’m talking about rustc flags. I get that every library using
I don’t think that will happen anytime soon, so I won't wait for that to happen.
The problem with that approach is how filtering would work. The current filtering system relies on the |
The lack of these levels is probably my top gripe with But, given the fact that |
Feature Request
Crates
tracing
tracing-core
Motivation
Currently, tracing supports five log levels:
trace
,debug
,info
,warn
anderror
. While these levels cover mostuse cases, there are scenarios where more nuanced control over log severity is needed. For example, the
info
level maygenerate excessive noise for certain events, while
warn
may be too severe. Similarly,error
may not prompt immediateuser action for critical events that require urgent attention.
Proposal
The additional log level will be inspired by
syslog
andopentelemetry
because most of the applications use theseas a standard. This proposal is not going to support every log level that both projects have but going to support only "
needed" and "nice to have" levels.
Syslog supports 8 log levels from
debug
toemergency
and OpenTelemetry supports 6 log levels fromtrace
to
fatal4
as shown in the table below:tracing
syslog
opentelemtry
emergency
fatal2
-fatal4
alert
critical
fatal
error
error
error
warn
warn
warn
notice
info2
-info4
info
info
info
debug
debug
debug
trace
trace
As shown in the table, most of the log levels between
syslog
andopentelemetry
overlap. The only differenceis
syslog
has no support fortrace
andopentelemetry
has no direct support foremergency
,alert
,notice
butit already provided a room for them.
So which log levels should be added? For me the most important log level that needs to be added as of now is
critical
and
it is nice to have a
notice
level. The level abovecritical
seems unnecessary because it's rarely used and the levelbelow
notice
is already supported byopentelemetry
.Why
notice
andcritical
?notice
: can be used for events that are significant but do not require immediate attention. This would fallbetween
info
andwarn
, highlighting noteworthy occurrences without generating excessive noise likeinfo
.critical
: can be used for events that require immediate user action. This would fall aboveerror
, indicating amore urgent situation where a failure or issue could have severe consequences if not addressed quickly.
How to implement
As I discussed with @hds in the
tracing-dev
discord channel, the implementation of this feature is likely to be messybecause the
Level
definition is used in many places in the codebase and third-party crates. This change will surelymake the codebase that relies on the
Level
definition such as the project that uses match expression to match the loglevel to be broken. So, the best way to implement this feature as of now is to hide it under a cfg flag. For the crate
authors that want to support this feature, the crate author needs to hide this feature under the same cfg flag.
We will discuss the use of cfg flags and what needs to be changed later in the comments.
The text was updated successfully, but these errors were encountered: