Skip to content
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

missing MakeVisitor impl for Pretty #3094

Open
wmmc88 opened this issue Oct 1, 2024 · 0 comments
Open

missing MakeVisitor impl for Pretty #3094

wmmc88 opened this issue Oct 1, 2024 · 0 comments

Comments

@wmmc88
Copy link

wmmc88 commented Oct 1, 2024

Bug Report

Version

tracing-subscriber v0.3.18
tracing-core v0.1.32
tracing-log v0.2.0

Platform

64Bit Windows 11

Crates

tracing-subscriber

Description

I am trying to enable pretty printing (i.e. :#?) in traces. According to this comment, the way to do this is via debug_alt:

use tracing_subscriber::field::MakeExt;

tracing_subscriber::fmt()
    .map_fmt_fields(|f| f.debug_alt())
    .init();

This works, but I want to be able to just use the pretty() subscriber builder, and just customize this one option. I thought I could do something like:

use tracing_subscriber::field::MakeExt;

tracing_subscriber::fmt()
    .pretty()
    .map_fmt_fields(|f| f.debug_alt())
    .init();

but this doesn't compile due to the following error:

error[E0599]: the method `debug_alt` exists for struct `Pretty`, but its trait bounds were not satisfied
  --> script.rs:21:27
   |
21 |     .map_fmt_fields(|f| f.debug_alt())
   |                           ^^^^^^^^^ method cannot be called on `Pretty` due to unsatisfied trait bounds
   |
  ::: D:\.tools\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tracing-subscriber-0.3.18\src\fmt\format\pretty.rs:99:1
   |
99 | pub struct Pretty {
   | ----------------- doesn't satisfy `Pretty: MakeExt<_>`, `Pretty: MakeVisitor<_>` or `_: Sealed<MakeExtMarker<_>>`
   |
   = note: the following trait bounds were not satisfied:
           `Pretty: MakeVisitor<_>`
           which is required by `Pretty: MakeExt<_>`
           `Pretty: tracing_subscriber::sealed::Sealed<MakeExtMarker<_>>`
           which is required by `Pretty: MakeExt<_>`
           `&Pretty: MakeVisitor<_>`
           which is required by `&Pretty: MakeExt<_>`
           `&Pretty: tracing_subscriber::sealed::Sealed<MakeExtMarker<_>>`
           which is required by `&Pretty: MakeExt<_>`
           `&mut Pretty: MakeVisitor<_>`
           which is required by `&mut Pretty: MakeExt<_>`
           `&mut Pretty: tracing_subscriber::sealed::Sealed<MakeExtMarker<_>>`
           which is required by `&mut Pretty: MakeExt<_>`

It looks like in the 2nd snippet, f is a Pretty which doesn't implement MakeVisitor so the blanket implementdation of MakeExt doesn't apply to it. This means that debug_alt doesnt exist for it. In the first snippet, it compiles because f is DefaultFields which implements MakeVisitor.

Is this just a bug or is there a reason that Pretty doesn't implement MakeVisitor? AFAIU, there is also a PrettyFields struct that does implement MakeVistor, but for some reason, fmt().pretty() returns a Builder that uses Pretty as the generic arg instead of PrettyFields. This diverges from the fmt().json() behavior which returns a JsonFields.

Is there a better way to achieve what I want to do?

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

1 participant