Skip to content

Configurable log level for #[instrument(err)] #2330

@nitnelave

Description

@nitnelave

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?

#[instrument(level="debug", ret, err, err_level="info")]
fn my_fun() -> Result<int> { Ok(42) }

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions