-
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
Configurable log level for #[instrument(err)]
#2330
Comments
This is similar to the discussion #2328, which is about configuring the log level for the event generated by the #[instrument(level="debug", ret, err(level = "info"))]
fn my_fun() -> Result<int> { Ok(42) } which i think might be a bit nicer, as it's slightly more concise, and introduces the possiblity to add additional configuration options for the I think adding this should probably be fairly straightforward, at least for a contributor who's familiar with proc-macro implementation. If you're interested in opening a PR to add something like this, I'm happy to answer any questions you might have! |
Alright, that sounds good! In the spirit of the discussions you linked to, I'd probably add the same feature for I'll try to have a swing at it, though it's my first foray into procedural macros. But hey, there's a start to everything! |
This branch adds the ability to override the level of the events generated by the `ret` and `err` arguments to `#[instrument]`. An overridden level can be specified with: ```rust #[instrument(ret(level = "info"))] ``` ```rust #[instrument(err(level = Level::Debug))] ``` and so on. This syntax is fully backwards compatible with existing uses of the attribute. In addition, some refactoring was done to how levels are parsed and how the tokens for a specified level is generated. Fixes #2330
This branch adds the ability to override the level of the events generated by the `ret` and `err` arguments to `#[instrument]`. An overridden level can be specified with: ```rust ``` ```rust ``` and so on. This syntax is fully backwards compatible with existing uses of the attribute. In addition, some refactoring was done to how levels are parsed and how the tokens for a specified level is generated. Fixes #2330 ; Conflicts: ; tracing-attributes/src/lib.rs
This branch adds the ability to override the level of the events generated by the `ret` and `err` arguments to `#[instrument]`. An overridden level can be specified with: ```rust ``` ```rust ``` and so on. This syntax is fully backwards compatible with existing uses of the attribute. In addition, some refactoring was done to how levels are parsed and how the tokens for a specified level is generated. Fixes #2330 ; Conflicts: ; tracing-attributes/src/lib.rs
This branch adds the ability to override the level of the events generated by the `ret` and `err` arguments to `#[instrument]`. An overridden level can be specified with: ```rust ``` ```rust ``` and so on. This syntax is fully backwards compatible with existing uses of the attribute. In addition, some refactoring was done to how levels are parsed and how the tokens for a specified level is generated. Fixes tokio-rs#2330 ; Conflicts: ; tracing-attributes/src/lib.rs
Feature Request
I'd like to be able to specify the log level that
Err
returns are printed at.Crates
tracing::instrument
Motivation
Currently it's hardcoded as
error
, but I have some functions that I'd like to instrument where returning an error is not especially unusual (think of for instance "is the user logged in yet?": any error eventually gets folded into "no, the user is not logged in"). In such cases, I'd like to be able to lower the level to WARN or INFO or even DEBUG.Proposal
How about an additional attribute
err_level
?Alternatives
I could avoid using the instrument macro and annotate every single caller with an event, but that's not really the spirit of the crate :)
The text was updated successfully, but these errors were encountered: