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: fix accessing the field formatter from FmtContext #1082

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Nov 2, 2020

This backports PR #1081 from v0.2.x. Since this has already been approved
on master, I'll just go ahead and merge it when CI passes.

Motivation

Currently, the FmtContext type implements FormatFields using the
subscriber's field formatter. However, this is difficult to use. The
FmtContext may not be passed to functions expecting a for<'writer> FormatFields<'writer>, because it only implements FormatFields for
its own lifetime. This means the writer must have the same lifetime as
the context, which is not correct.

Solution

This branch fixes this by changing the impl of FormatFields for
FmtContext to be generic over both the context's lifetime and the
field formatter's lifetime. Additionally, I've added a method for
borrowing the actual field formatter as its concrete type, in case the
FormatEvent impl puts additional constraints on its type or is only
implemented for a specific named type, and wants to actually use that
type.

This backports PR #1081 from v0.2.x.

Motivation

Currently, the `FmtContext` type implements `FormatFields` using the
subscriber's field formatter. However, this is difficult to use. The
`FmtContext` may _not_ be passed to functions expecting a `for<'writer>
FormatFields<'writer>`, because it only implements `FormatFields` for
its _own_ lifetime. This means the writer must have the same lifetime as
the context, which is not correct.

Solution

This branch fixes this by changing the impl of `FormatFields` for
`FmtContext` to be generic over both the context's lifetime _and_ the
field formatter's lifetime. Additionally, I've added a method for
borrowing the actual field formatter as its concrete type, in case the
`FormatEvent` impl puts additional constraints on its type or is only
implemented for a specific named type, and wants to actually _use_ that
type.
@hawkw hawkw requested a review from a team as a code owner November 2, 2020 21:20
@hawkw hawkw merged commit 2d27703 into v0.1.x Nov 2, 2020
hawkw added a commit that referenced this pull request Nov 2, 2020
Fixed

- **fmt**: Fixed wrong lifetime parameters on `FormatFields` impl for
  `FmtContext` ([#1082])

Added

- **fmt**: `format::Pretty`, an aesthetically pleasing, human-readable
  event formatter for local development and user-facing CLIs ([#1080])
- **fmt**: `FmtContext::field_format`, which returns the subscriber's
  field formatter ([#1082])

[#1082]: #1082
[#1080]: #1080
hawkw added a commit that referenced this pull request Nov 2, 2020
### Fixed

- **fmt**: Fixed wrong lifetime parameters on `FormatFields` impl for
  `FmtContext` ([#1082])

### Added

- **fmt**: `format::Pretty`, an aesthetically pleasing, human-readable
  event formatter for local development and user-facing CLIs ([#1080])
- **fmt**: `FmtContext::field_format`, which returns the subscriber's
  field formatter ([#1082])

[#1082]: #1082
[#1080]: #1080
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
…o-rs#1081) (tokio-rs#1082)

This backports PR tokio-rs#1081 from v0.2.x. Since this has already been approved
on master, I'll just go ahead and merge it when CI passes.

## Motivation

Currently, the `FmtContext` type implements `FormatFields` using the
subscriber's field formatter. However, this is difficult to use. The
`FmtContext` may _not_ be passed to functions expecting a `for<'writer>
FormatFields<'writer>`, because it only implements `FormatFields` for
its _own_ lifetime. This means the writer must have the same lifetime as
the context, which is not correct.

## Solution

This branch fixes this by changing the impl of `FormatFields` for
`FmtContext` to be generic over both the context's lifetime _and_ the
field formatter's lifetime. Additionally, I've added a method for
borrowing the actual field formatter as its concrete type, in case the
`FormatEvent` impl puts additional constraints on its type or is only
implemented for a specific named type, and wants to actually _use_ that
type.
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
### Fixed

- **fmt**: Fixed wrong lifetime parameters on `FormatFields` impl for
  `FmtContext` ([tokio-rs#1082])

### Added

- **fmt**: `format::Pretty`, an aesthetically pleasing, human-readable
  event formatter for local development and user-facing CLIs ([tokio-rs#1080])
- **fmt**: `FmtContext::field_format`, which returns the subscriber's
  field formatter ([tokio-rs#1082])

[tokio-rs#1082]: tokio-rs#1082
[tokio-rs#1080]: tokio-rs#1080
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.

None yet

1 participant