Skip to content

[Feature request] Allow skipping arguments and return values #18

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

Open
myypo opened this issue Mar 26, 2025 · 2 comments
Open

[Feature request] Allow skipping arguments and return values #18

myypo opened this issue Mar 26, 2025 · 2 comments

Comments

@myypo
Copy link

myypo commented Mar 26, 2025

It would have been great to have an ability to skip certain arguments or all arguments altogether and also not have to have Debug implementation for not logged values.

The reason being that not all arguments/returns can provide reasonable implementations of Debug. Docs of a similiar feature in tokio tracing: https://docs.rs/tracing/latest/tracing/attr.instrument.html#skipping-fields

Not sure yet how difficult it is to implement but in a perfect world it would have been possible to:

  1. Choose to skip certain arguments.
  2. Choose to skip all arguments.
  3. Require Debug only if the value will be actually logged.
/// Logs errors at the `error` level. No log output for `Ok` variant.
#[logcall(err = "error")]
fn divide2(a: usize, b: usize) -> Result<usize, String> {
    if b == 0 {
        Err("Division by zero".to_string())
    } else {
        Ok(a / b)
    }
}
@andylokandy
Copy link
Collaborator

andylokandy commented Mar 27, 2025

Yes, I agree it's convenient to have an attribute config to skip some of the fields. Currently, you could skip all by denoting #[logcall(input = "")] to prevent it from outputting arguments, and also you could manually write the input format string to fine-grained control which arguments to print and using whether Debug/Display like#[logcall(input = "a = {a:?}")].

@myypo
Copy link
Author

myypo commented Mar 27, 2025

Unfortunately it seems to me like currently there is no workaround that allows to compile something like this:

struct NonDebuggable;

#[logcall(input = "")]
fn call() -> NonDebuggable {
    NonDebuggable {}
}

Because the macro requires all of the function parameters as well as the return value to implement Debug.

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