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

subscriber: update pretty formatter for no ansi #1240

Merged
merged 11 commits into from
Mar 11, 2021

Commits on Mar 11, 2021

  1. subscriber: update pretty formatter for no ansi

     ## Background
    
        Currently, when the `Pretty` event formatter is being used, it does
        not change its output when the `with_ansi` flag is set to false by
        the `CollectorBuilder`.
    
     ## Overview
    
        While this formatter is generally used in situations such as local
        development, where ANSI escape codes are more often acceptable,
        there are some situations in which this can lead to mangled output.
    
        This commit makes some minor changes to account for this `ansi` flag
        when formatting events using `Pretty`.
    
        Becuase ANSI codes were previously used to imply the event level
        using colors, this commit additionally modifies `Pretty` so that
        it respects `display_level` when formatting an event.
    
     ## Changes
    
        * Changes to `<Format<Pretty, T> as FormatEvent<C, N>>::format_event`
    
        * Implement `LevelNames` for `Pretty`, copying `Full`'s
          implementation.
    
        * Add a `PrettyVisitor::ansi` boolean flag, used in its `Visit`
          implementation.
    
            * Add a new `PrettyVisitor::with_ansi` builder pattern method to
              facilitate this.
    
     ## Out of Scope
    
        One detail worth nothing is that this does not solve the problem of
        *fields* being formatted without ANSI codes. Configuring a
        subscriber using this snippet would still lead to bolded fields in
        parent spans.
    
    ```rust
    tracing_subscriber::fmt()
        .pretty()
        .with_ansi(false)
        .with_level(false)
        .with_max_level(tracing::Level::TRACE)
        .init();
    ```
    
        This can be worked around by using a different field formatter, via
        `.fmt_fields(tracing_subscriber::fmt::format::DefaultFields::new())`
        in the short-term.
    
        In the long-term, tokio-rs#658 is worth investigating further.
    
    Refs: tokio-rs#658
    katelyn martin committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    0788fc3 View commit details
    Browse the repository at this point in the history
  2. subscriber: add missing cfg attribute

    katelyn martin committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    9c837ac View commit details
    Browse the repository at this point in the history
  3. subscriber: add inherent bold method (review)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    katelyn martin and hawkw committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    2025f5e View commit details
    Browse the repository at this point in the history
  4. subscriber: add new PrettyFields struct (review)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    katelyn martin and hawkw committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    603fbff View commit details
    Browse the repository at this point in the history
  5. subscriber: document ansi behavior of pretty() (review)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    katelyn martin and hawkw committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    80a9396 View commit details
    Browse the repository at this point in the history
  6. subscriber: clarify comment on ansi codes (review)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    katelyn martin and hawkw committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    45f21dc View commit details
    Browse the repository at this point in the history
  7. subscriber: add missing whitespace (review)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    katelyn martin and hawkw committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    c017573 View commit details
    Browse the repository at this point in the history
  8. subscriber: move PrettyFields, remove _private (review)

    Co-authored-by: Eliza Weisman <eliza@buoyant.io>
    katelyn martin and hawkw committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    779f53b View commit details
    Browse the repository at this point in the history
  9. subscriber: katie did an oopsie

    katelyn martin committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    5f6cb42 View commit details
    Browse the repository at this point in the history
  10. subscriber: katie did *two* oopsies

    katelyn martin committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    e990936 View commit details
    Browse the repository at this point in the history
  11. subsciber: fix doc test (three oopsies)

    katelyn martin committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    2d23a01 View commit details
    Browse the repository at this point in the history