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

Conversation

cratelyn
Copy link
Contributor

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.

Now, installing a subscriber like so...

    tracing_subscriber::fmt()
        .pretty()
        .with_thread_names(true)
        .with_ansi(false)
        .with_level(true)
        .with_max_level(tracing::Level::TRACE)
        .init();

...will lead to logs that look like this:

pretty-no-ansi

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.

tracing_subscriber::fmt()
    .pretty()
    .with_ansi(false)
    .with_level(true)
    .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, #658 is worth investigating further.

@cratelyn cratelyn requested review from davidbarsky, hawkw and a team as code owners February 16, 2021 15:41
@cratelyn
Copy link
Contributor Author

Alas! I've missed some CI checks. I'll resolve these later today 🙂

@hawkw
Copy link
Member

hawkw commented Feb 16, 2021

Alas! I've missed some CI checks. I'll resolve these later today slightly_smiling_face

I think the checks that are failing are the ones that test various feature combinations. In particular, it looks like the new code doesn't compile when the ansi feature flag is disabled. I think we want to add #[cfg(feature = "ansi")] attributes to the code that constructs Styles, similar to the other formatters:

#[cfg(feature = "ansi")]
let dimmed = if self.ansi {
Style::new().dimmed()
} else {
Style::new()
};

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, this looks great --- I think the only issue is that we need to correctly handle the "ansi" feature flag being disabled at compile-time, which should fix CI. once that's taken care of, this should be good to merge!

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.

tracing_subscriber::fmt()
    .pretty()
    .with_ansi(false)
    .with_level(true)
    .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, #658 is worth investigating further.

I think a potential short term solution to this is just adding a bit to the docs explaining that the Pretty field formatter always includes ANSI color codes, so that users who are using the Pretty event formatter know that if they want to disable ANSI colors, they need to provide a different field formatter. Ideally, we definitely want this to just work correctly, but in the meantime it would be good to at least document the current behavior.

We might also want to add a new public PrettyFields field formatter type that makes the PrettyVisitor type (which would have to be made public, but its constructors could remain private). This could have an option to enable/disable ANSI, so that users can get the same style formatting with ANSI color codes disabled, rather than using the default field formatter. Users would have to write something like this:

tracing_subscriber::fmt()
    .pretty()
    .with_ansi(false)
    .fmt_fields(format::PrettyFields::new().with_ansi(false))
    // ... other settings ...
    .init();

which is a little bit redundant, but at least it would be possible to get consistent punctuation without having to reimplement the Pretty field formatter in user code.

We could make that change in a separate, follow-up PR.

Comment on lines 288 to 292
let bold = if self.ansi {
self.style.bold()
} else {
Style::new()
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, take it or leave it: we could factor this out into an inherent method on PrettyVisitor, since it shows up a couple of times. not a blocker though, up to you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in 3c6b46c

@hawkw
Copy link
Member

hawkw commented Feb 26, 2021

Any updates on this one?

@cratelyn
Copy link
Contributor Author

Any updates on this one?

Oh my goodness was this actually 10 days ago? I'll address the feedback above and should have this ready for another look very soon. My apologies!

@hawkw
Copy link
Member

hawkw commented Feb 26, 2021

No rush, just wanted to make sure it wasn't blocked on me :)

@cratelyn
Copy link
Contributor Author

No rush, just wanted to make sure it wasn't blocked on me :)

Not at all! Blocked on "my brain, she is very sick."

@cratelyn
Copy link
Contributor Author

cratelyn commented Mar 9, 2021

Pardon, I'm a smidge unfamiliar with the CI setup for tracing. It looks like the failures in warnings, test-versions, test-msrv, et. al. are unrelated, mostly something to do with async_fn_with_async_trait cases?

Going off of the "Merging can be performed automatically with 1 approving review." I'm guessing those are optional CI jobs, but I wanted to make sure I was understanding that correctly.

@hawkw
Copy link
Member

hawkw commented Mar 11, 2021

Pardon, I'm a smidge unfamiliar with the CI setup for tracing. It looks like the failures in warnings, test-versions, test-msrv, et. al. are unrelated, mostly something to do with async_fn_with_async_trait cases?

Sorry, this was an unrelated issue due to an upstream change that broke the async-trait support for tracing-attributes. It's been fixed now; if we update this with the latest master, i think we should be able to get a clean CI build.

@cratelyn
Copy link
Contributor Author

Sounds good! I'll update this branch now 🚀

@hawkw
Copy link
Member

hawkw commented Mar 11, 2021

Latest CI failure is a known flaky test that i should really probably just remove. I'll restart the build.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, this looks good! it might be nice to have a test for whether or not ANSI escape codes are present in output when they're disabled this way, but it's not a blocker.

it would be nice to remove the "ansi" feature flag requirement from the Pretty formatter, but that's a bigger change, so we can do that in a future PR. currently the code in other formatters for handling the "ansi" feature flag is quite messy. we might want to consider an approach that would be a bit neater, like having a module with a no-op Style type in it (all the same methods as ansi_term's Style, but they just do nothing), when the feature is not set, and reexporting ansi_term::Style when it is set. this way, we wouldn't need to stick nearly as many cfg attributes in the actual formatter code to handle the feature-flagging.

anyway, that's just a thought, this looks great! thank you!

tracing-subscriber/src/fmt/format/mod.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/format/mod.rs Outdated Show resolved Hide resolved
Comment on lines 312 to 314
#[cfg(feature = "ansi")]
#[cfg_attr(docsrs, doc(cfg(feature = "ansi")))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the "ansi" feature flag now that this doesn't depend on ANSI formatting? we would have to change it to default to no-ANSI formatting when the ansi feature flag is disabled, and update the code so that all the use of Styles is feature flagged, like the other formatters.

it would be fine to do this in a follow-up PR after this change lands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to do that! If it's alright, I'd like to do that in a follow-up PR, as I suspect it'll be slightly involved. If it works for you, feel free to create and assign an issue for me 🙂

tracing-subscriber/src/fmt/format/pretty.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/format/pretty.rs Outdated Show resolved Hide resolved
katelyn martin and others added 3 commits March 11, 2021 16:42
 ## 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
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
katelyn martin and others added 5 commits March 11, 2021 16:44
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
This was referenced Mar 15, 2021
bors bot referenced this pull request in comit-network/comit-rs Mar 17, 2021
3532: Bump tracing-subscriber from 0.2.15 to 0.2.17 r=mergify[bot] a=dependabot[bot]

Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.15 to 0.2.17.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/tokio-rs/tracing/commit/88685417f66ae7b74df57f56ebe28256dc9fd7ff"><code>8868541</code></a> subscriber: prepare to release 0.2.17 (<a href="https://github.com/tokio-rs/tracing/issues/1302">#1302</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/742b21461bffc59c60ba4d5726e752144b3fffc3"><code>742b214</code></a> attributes: prepare to release v0.1.15 (<a href="https://github.com/tokio-rs/tracing/issues/1301">#1301</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/ec7313466dbe615ed8397422bc0aa34280dec0a6"><code>ec73134</code></a> subscriber: update pretty formatter for no ansi (<a href="https://github.com/tokio-rs/tracing/issues/1240">#1240</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/a947c5a63f73b840d100ee85638e90a3488f9789"><code>a947c5a</code></a> subscriber: change <code>FmtSpan</code> to a combinable bitflag (<a href="https://github.com/tokio-rs/tracing/issues/1277">#1277</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/f3eb5ccf2dc128ef171a2320bff488c144903376"><code>f3eb5cc</code></a> subscriber: fix extra padding in pretty format (<a href="https://github.com/tokio-rs/tracing/issues/1275">#1275</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/ac0aa9763b434885bba27db7334683c0e5665e97"><code>ac0aa97</code></a> attributes: fix <code>#[instrument]</code> skipping code when returning pinned futures (...</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/544da6b5d8b489cee084974100514e38fe25b6ec"><code>544da6b</code></a> subscriber: Add a public <code>current_span()</code> method for <code>FmtContext</code> (<a href="https://github.com/tokio-rs/tracing/issues/1290">#1290</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/14d11ebdd60db0955806d10d31345a54a79a38f7"><code>14d11eb</code></a> subscriber: remove unnecessary transparent attribute (<a href="https://github.com/tokio-rs/tracing/issues/1282">#1282</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/51812267b8af46244c412cf0490391d024e60902"><code>5181226</code></a> subscriber: use struct update syntax when constructing from <code>self</code> (<a href="https://github.com/tokio-rs/tracing/issues/1289">#1289</a>)</li>
<li><a href="https://github.com/tokio-rs/tracing/commit/6f9b537c2ebbfb73c57b5c40dc25e011eb1b4d7c"><code>6f9b537</code></a> subscriber: Remove trailing space from ChronoLocal time formatter. (<a href="https://github.com/tokio-rs/tracing/issues/1103">#1103</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.15...tracing-subscriber-0.2.17">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tracing-subscriber&package-manager=cargo&previous-version=0.2.15&new-version=0.2.17)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually


</details>

3533: Bump socket2 from 0.3.19 to 0.4.0 r=mergify[bot] a=dependabot[bot]

Bumps [socket2](https://github.com/rust-lang/socket2) from 0.3.19 to 0.4.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/rust-lang/socket2/blob/master/CHANGELOG.md">socket2's changelog</a>.</em></p>
<blockquote>
<h1>0.4.0</h1>
<h2>Added</h2>
<ul>
<li>New <code>all</code> feature: enables API that is not available on all tier 1 platforms.</li>
<li><code>SockRef</code> type: used to create a reference to an existing socket, e.g.
<code>std::net::TcpStream</code>, making all methods of <code>Socket</code> available on it.</li>
<li>Support for vectored I/O:
<ul>
<li><code>Socket::recv_vectored</code>, <code>Socket::recv_with_flags</code>.</li>
<li><code>Socket::recv_from_vectored</code>, <code>Socket::recv_from_vectored_with_flags</code>.</li>
<li><code>Socket::send_vectored</code>, <code>Socket::send_vectored_with_flags</code>.</li>
<li><code>Socket::send_to_vectored</code>, <code>Socket::send_to_vectored_with_flags</code>.</li>
<li>In the <code>Read</code> and <code>Write</code> implementations.</li>
</ul>
</li>
<li><code>Socket::new_raw</code>, <code>Socket::pair_raw</code> and <code>Socket::accept_raw</code> methods
that don't set common flags, such as the close-on-exec flag.</li>
<li><code>Socket::accept4</code>: <code>accept4(2)</code> system call.</li>
<li><code>Socket::sendfile</code>: the <code>sendfile(2)</code> system call.</li>
<li><code>Socket::set_cloexec</code>: set the close-on-exec flag on Unix.</li>
<li><code>Socket::set_no_inherit</code>: set inherit handle flag on Windows.</li>
<li><code>Socket::set_nosigpipe</code>: set <code>SO_NOSIGPIPE</code> on Apple targets.</li>
<li><code>Socket::set_mark</code> and <code>Socket::mark</code>, setting/getting the <code>SO_MARK</code> socket
option.</li>
<li><code>Socket::set_cpu_affinity</code> and <code>Socket::cpu_affinity</code>, setting/getting the
<code>SO_INCOMING_CPU</code> socket option.</li>
<li><code>Socket::set_mss</code> and <code>Socket::mss</code>, setting/getting the <code>TCP_MAXSEG</code> socket
option.</li>
<li><code>Socket::set_freebind</code> and <code>Socket::freebind</code>, setting/getting the
<code>IP_FREEBIND</code> socket option.</li>
<li><code>Socket::bind_device</code> and <code>Socket::device</code>, setting/getting the
<code>SO_BINDTODEVICE</code> socket option.</li>
<li>Adopted Mio's TCP keepalive API:
<ul>
<li><code>Socket::keepalive_time</code>,</li>
<li><code>Socket::keepalive_interval</code>,</li>
<li><code>Socket::keepalive_retries</code>,</li>
<li><code>Socket::set_tcp_keepalive</code>.</li>
</ul>
</li>
<li><code>Socket::is_listener</code> getting the <code>SO_ACCEPTCONN</code> socket option.</li>
<li><code>Socket::domain</code> getting the <code>SO_DOMAIN</code> socket option.</li>
<li><code>Socket::protocol</code> getting the <code>SO_PROTOCOL</code> socket option.</li>
<li><code>Socket::type</code> getting the <code>SO_TYPE</code> socket option.</li>
<li><code>Domain::for_address</code>: the correct <code>Domain</code> for a <code>std::net::SocketAddr</code>.</li>
<li><code>Type::nonblocking</code>: set <code>SOCK_NONBLOCK</code>.</li>
<li><code>Type::cloexec</code>: set <code>SOCK_CLOEXEC</code>.</li>
<li><code>Type::no_inherit</code>: set <code>HANDLE_FLAG_INHERIT</code>.</li>
<li><code>SockAddr::init</code>: initialises a <code>SockAddr</code>.</li>
<li><code>MaybeUninitSlice</code> type: a version of <code>IoSliceMut</code> that allows the buffer to
be uninitialised, used in <code>Socket::recv_vectored</code> and related functions.</li>
<li><code>RecvFlags</code> type: provides additional information about incoming messages,
returned by <code>Socket::recv_vectored</code> and related functions.</li>
<li><code>TcpKeepalive</code> type: configuration type for a socket's TCP keepalive
parameters.</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/rust-lang/socket2/commit/b1479fffa0749147eabd15ad9038d0f9a0cc7825"><code>b1479ff</code></a> Release v0.4.0</li>
<li><a href="https://github.com/rust-lang/socket2/commit/adf32dabfc5c152af8488161b1d99512c8b8b054"><code>adf32da</code></a> Use SO_LINGER_SEC for Socket::get/set_linger on macOS</li>
<li><a href="https://github.com/rust-lang/socket2/commit/559ba4290899002406bb4c89caef7905a186ba0a"><code>559ba42</code></a> Fuchsia doesn't support <code>sendfile</code></li>
<li><a href="https://github.com/rust-lang/socket2/commit/94c32b95921c13740abfa8a109acc821a4f2ed05"><code>94c32b9</code></a> Release v0.4.0-alpha.5</li>
<li><a href="https://github.com/rust-lang/socket2/commit/ca694de9a75f52607693704dc0fa6fa7573b089d"><code>ca694de</code></a> Change Socket::(set_)cpu_affinity to take an immutable reference</li>
<li><a href="https://github.com/rust-lang/socket2/commit/4f643fc66fd6ab52d86477a6d93dd04dd209115a"><code>4f643fc</code></a> Release v0.4.0-alpha.4</li>
<li><a href="https://github.com/rust-lang/socket2/commit/c3b447e1597886fc81c12ba108201944235569b1"><code>c3b447e</code></a> Add Socket::(set_)cpu_affinity</li>
<li><a href="https://github.com/rust-lang/socket2/commit/33da3507f8e5205f7a66654b8349aec112447ef6"><code>33da350</code></a> Release v0.4.0-alpha.3</li>
<li><a href="https://github.com/rust-lang/socket2/commit/4f22376fc1fba8062f756e2c4f4bdf7d05ede5a9"><code>4f22376</code></a> tests: add vsock test</li>
<li><a href="https://github.com/rust-lang/socket2/commit/07c7b373615e1011f51e79269960d72fe006f089"><code>07c7b37</code></a> unix: add SockAddr::vsock_address()</li>
<li>Additional commits viewable in <a href="https://github.com/rust-lang/socket2/compare/v0.3.19...v0.4.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=socket2&package-manager=cargo&previous-version=0.3.19&new-version=0.4.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@cratelyn cratelyn deleted the fmt-pretty-no-ansi branch March 17, 2021 23:08
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
This backports tokio-rs#1240 from `master`.

* 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`

    * 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
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.2.17 (March 12, 2020)

### Fixed

- **fmt**: `Pretty` formatter now honors `with_ansi(false)` to disable
  ANSI terminal formatting ([tokio-rs#1240])
- **fmt**: Fixed extra padding when using `Pretty` formatter ([tokio-rs#1275])
- **chrono**: Removed extra trailing space with `ChronoLocal` time
  formatter ([tokio-rs#1103])

### Added

- **fmt**: Added `FmtContext::current_span()` method, returning the
  current span
  ([tokio-rs#1290])
- **fmt**: `FmtSpan` variants may now be combined using the `|` operator
  for more granular control over what span events are generated
  ([tokio-rs#1277])

Thanks to new contributors @cratelyn, @dignati, and @zicklag, as well as
@Folyd, @matklad, and @najamelan, for contributing to this release!

[tokio-rs#1240]: tokio-rs#1240
[tokio-rs#1275]: tokio-rs#1275
[tokio-rs#1103]: tokio-rs#1103
[tokio-rs#1290]: tokio-rs#1290
[tokio-rs#1277]: tokio-rs#1277
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

Successfully merging this pull request may close these issues.

2 participants