tracing icon indicating copy to clipboard operation
tracing copied to clipboard

missing `MakeVisitor` impl for `Pretty`

Open wmmc88 opened this issue 4 months ago • 0 comments

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 but 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?

wmmc88 avatar Oct 01 '24 02:10 wmmc88