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: Add SubscriberBuilder/Layer accessors #1871

Merged
merged 4 commits into from
Jan 28, 2022

Conversation

lilyball
Copy link
Contributor

Motivation

SubscriberBuilders and Layers configured with custom event/field formatters do not provide any means of accessing or mutating those formatters. Any configuration that needs to be done must be done before setting them on the builder/layer. This is frustrating as it makes it difficult to provide a pre-configured API akin to tracing_subscriber::fmt() along with accessors like .compact() that modify the formatter.

Solution

Add accessors .map_event_format() and .map_fmt_fields() to SubscriberBuilder and Layer that map the existing formatter through a closure. This allows the closure to modify it or to derive a new formatter from it with a different type.

Also add a .map_writer() method that does the same thing for the MakeWriter, to round out the accessors for the various type parameters.

The filter type is currently restricted to just LevelFilter or EnvFilter and so this does not add a corresponding .map_filter(). That can be added later if we add the ability to attach arbitrary filters.

Also fix some minor docs issues that were spotted as part of implementing this.

Fixes #1756

These are added to both `Layer` and `SubscriberBuilder`. These allow
users to accept preconfigured layers/builders and update them. In
particular, these should allow crates that have custom formatters to
expose an equivalent to `tracing_subscriber::fmt()` and allow the user
to customize the preconfigured formatters.

Fixes tokio-rs#1756
This adds `SubscriberBuilder::map_writer()` and `Layer::map_writer()`,
which are similar to the `map_event_format()` and `map_fmt_fields()`
methods.
@lilyball lilyball requested review from hawkw and a team as code owners January 27, 2022 23:13
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 to me, thank you!

The only potential consideration is that i've been wondering if the fmt_fields() function should be renamed to field_format(), for consistency with the event_format() function (which would require a deprecation cycle). I wonder if it might be better to call the map_fmt_fields added in this PR map_field_format, instead, in anticipation of the renaming, so that we don't have to deprecate as many APIs.

What do you think?

@lilyball
Copy link
Contributor Author

My feeling is it should match the current name, whatever it is, to make it easier to understand without having to read up on it. I do agree that fmt_fields() should be renamed, so I would suggest that we start with map_fmt_fields() and simply rename it at the same time as fmt_fields() is renamed.

@hawkw
Copy link
Member

hawkw commented Jan 28, 2022

Okay, let's go ahead and get this merged, and we can rename all the field formatter APIs separately.

Thanks for the PR!

@hawkw hawkw enabled auto-merge (squash) January 28, 2022 17:37
@hawkw hawkw merged commit bcd0972 into tokio-rs:v0.1.x Jan 28, 2022
@lilyball lilyball deleted the lily/event-field-formatter-accessors branch January 28, 2022 19:51
hawkw added a commit that referenced this pull request Feb 4, 2022
# 0.3.8 (Feb 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate to the `format::Json` formatter. In
particular, user-defined types which are recorded using their
[`valuable::Valuable`] implementations will be serialized as JSON
objects, rather than using their `fmt::Debug` representation. See [this
blog post][post] for details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

Additionally, this release includes a number of other smaller API
improvements.

### Added

- **json**: Experimental support for recording [`valuable`] values as
  structured JSON ([#1862], [#1901])
- **filter**: `Targets::would_enable` method for testing if a `Targets`
  filter would enable a given target ([#1903])
- **fmt**: `map_event_format`, `map_fmt_fields`, and `map_writer`
  methods to `fmt::Layer` and `fmt::SubscriberBuilder` ([#1871])

### Changed

- `tracing-core`: updated to [0.1.22][core-0.1.22]

### Fixed

- Set `smallvec` minimal version to 1.2.0, to fix compilation errors
  with `-Z minimal-versions` ([#1890])
- Minor documentation fixes ([#1902], [#1893])

Thanks to @guswynn, @glts, and @lilyball for contributing to this
release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
[post]: https://tokio.rs/blog/2021-05-valuable
[core-0.1.22]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.22
[#1862]: #1862
[#1901]: #1901
[#1903]: #1903
[#1871]: #1871
[#1890]: #1890
[#1902]: #1902
[#1893]: #1893
hawkw added a commit that referenced this pull request Feb 4, 2022
# 0.3.8 (Feb 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate to the `format::Json` formatter. In
particular, user-defined types which are recorded using their
[`valuable::Valuable`] implementations will be serialized as JSON
objects, rather than using their `fmt::Debug` representation. See [this
blog post][post] for details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

Additionally, this release includes a number of other smaller API
improvements.

### Added

- **json**: Experimental support for recording [`valuable`] values as
  structured JSON ([#1862], [#1901])
- **filter**: `Targets::would_enable` method for testing if a `Targets`
  filter would enable a given target ([#1903])
- **fmt**: `map_event_format`, `map_fmt_fields`, and `map_writer`
  methods to `fmt::Layer` and `fmt::SubscriberBuilder` ([#1871])

### Changed

- `tracing-core`: updated to [0.1.22][core-0.1.22]

### Fixed

- Set `smallvec` minimal version to 1.2.0, to fix compilation errors
  with `-Z minimal-versions` ([#1890])
- Minor documentation fixes ([#1902], [#1893])

Thanks to @guswynn, @glts, and @lilyball for contributing to this
release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
[post]: https://tokio.rs/blog/2021-05-valuable
[core-0.1.22]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.22
[#1862]: #1862
[#1901]: #1901
[#1903]: #1903
[#1871]: #1871
[#1890]: #1890
[#1902]: #1902
[#1893]: #1893
davidbarsky pushed a commit that referenced this pull request Aug 24, 2022
`SubscriberBuilder`s and `Layer`s configured with custom event/field
formatters do not provide any means of accessing or mutating those
formatters. Any configuration that needs to be done must be done before
setting them on the builder/layer. This is frustrating as it makes it
difficult to provide a pre-configured API akin to
`tracing_subscriber::fmt()` along with accessors like `.compact()` that
modify the formatter.

Add accessors `.map_event_format()` and `.map_fmt_fields()` to
`SubscriberBuilder` and `Layer` that map the existing formatter through
a closure. This allows the closure to modify it or to derive a new
formatter from it with a different type.

Also add a `.map_writer()` method that does the same thing for the
`MakeWriter`, to round out the accessors for the various type
parameters.

The filter type is currently restricted to just `LevelFilter` or
`EnvFilter` and so this does not add a corresponding `.map_filter()`.
That can be added later if we add the ability to attach arbitrary
filters.

Also fix some minor docs issues that were spotted as part of
implementing this.

Fixes #1756
davidbarsky pushed a commit that referenced this pull request Aug 24, 2022
`SubscriberBuilder`s and `Layer`s configured with custom event/field
formatters do not provide any means of accessing or mutating those
formatters. Any configuration that needs to be done must be done before
setting them on the builder/layer. This is frustrating as it makes it
difficult to provide a pre-configured API akin to
`tracing_subscriber::fmt()` along with accessors like `.compact()` that
modify the formatter.

Add accessors `.map_event_format()` and `.map_fmt_fields()` to
`SubscriberBuilder` and `Layer` that map the existing formatter through
a closure. This allows the closure to modify it or to derive a new
formatter from it with a different type.

Also add a `.map_writer()` method that does the same thing for the
`MakeWriter`, to round out the accessors for the various type
parameters.

The filter type is currently restricted to just `LevelFilter` or
`EnvFilter` and so this does not add a corresponding `.map_filter()`.
That can be added later if we add the ability to attach arbitrary
filters.

Also fix some minor docs issues that were spotted as part of
implementing this.

Fixes #1756
davidbarsky pushed a commit that referenced this pull request Aug 24, 2022
`SubscriberBuilder`s and `Layer`s configured with custom event/field
formatters do not provide any means of accessing or mutating those
formatters. Any configuration that needs to be done must be done before
setting them on the builder/layer. This is frustrating as it makes it
difficult to provide a pre-configured API akin to
`tracing_subscriber::fmt()` along with accessors like `.compact()` that
modify the formatter.

Add accessors `.map_event_format()` and `.map_fmt_fields()` to
`SubscriberBuilder` and `Layer` that map the existing formatter through
a closure. This allows the closure to modify it or to derive a new
formatter from it with a different type.

Also add a `.map_writer()` method that does the same thing for the
`MakeWriter`, to round out the accessors for the various type
parameters.

The filter type is currently restricted to just `LevelFilter` or
`EnvFilter` and so this does not add a corresponding `.map_filter()`.
That can be added later if we add the ability to attach arbitrary
filters.

Also fix some minor docs issues that were spotted as part of
implementing this.

Fixes #1756
hawkw pushed a commit that referenced this pull request Aug 24, 2022
`SubscriberBuilder`s and `Layer`s configured with custom event/field
formatters do not provide any means of accessing or mutating those
formatters. Any configuration that needs to be done must be done before
setting them on the builder/layer. This is frustrating as it makes it
difficult to provide a pre-configured API akin to
`tracing_subscriber::fmt()` along with accessors like `.compact()` that
modify the formatter.

Add accessors `.map_event_format()` and `.map_fmt_fields()` to
`SubscriberBuilder` and `Layer` that map the existing formatter through
a closure. This allows the closure to modify it or to derive a new
formatter from it with a different type.

Also add a `.map_writer()` method that does the same thing for the
`MakeWriter`, to round out the accessors for the various type
parameters.

The filter type is currently restricted to just `LevelFilter` or
`EnvFilter` and so this does not add a corresponding `.map_filter()`.
That can be added later if we add the ability to attach arbitrary
filters.

Also fix some minor docs issues that were spotted as part of
implementing this.

Fixes #1756
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
## Motivation

`SubscriberBuilder`s and `Layer`s configured with custom event/field
formatters do not provide any means of accessing or mutating those
formatters. Any configuration that needs to be done must be done before
setting them on the builder/layer. This is frustrating as it makes it
difficult to provide a pre-configured API akin to
`tracing_subscriber::fmt()` along with accessors like `.compact()` that
modify the formatter.

## Solution

Add accessors `.map_event_format()` and `.map_fmt_fields()` to
`SubscriberBuilder` and `Layer` that map the existing formatter through
a closure. This allows the closure to modify it or to derive a new
formatter from it with a different type.

Also add a `.map_writer()` method that does the same thing for the
`MakeWriter`, to round out the accessors for the various type
parameters.

The filter type is currently restricted to just `LevelFilter` or
`EnvFilter` and so this does not add a corresponding `.map_filter()`.
That can be added later if we add the ability to attach arbitrary
filters.

Also fix some minor docs issues that were spotted as part of
implementing this.

Fixes tokio-rs#1756
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.3.8 (Feb 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate to the `format::Json` formatter. In
particular, user-defined types which are recorded using their
[`valuable::Valuable`] implementations will be serialized as JSON
objects, rather than using their `fmt::Debug` representation. See [this
blog post][post] for details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

Additionally, this release includes a number of other smaller API
improvements.

### Added

- **json**: Experimental support for recording [`valuable`] values as
  structured JSON ([tokio-rs#1862], [tokio-rs#1901])
- **filter**: `Targets::would_enable` method for testing if a `Targets`
  filter would enable a given target ([tokio-rs#1903])
- **fmt**: `map_event_format`, `map_fmt_fields`, and `map_writer`
  methods to `fmt::Layer` and `fmt::SubscriberBuilder` ([tokio-rs#1871])

### Changed

- `tracing-core`: updated to [0.1.22][core-0.1.22]

### Fixed

- Set `smallvec` minimal version to 1.2.0, to fix compilation errors
  with `-Z minimal-versions` ([tokio-rs#1890])
- Minor documentation fixes ([tokio-rs#1902], [tokio-rs#1893])

Thanks to @guswynn, @glts, and @lilyball for contributing to this
release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
[post]: https://tokio.rs/blog/2021-05-valuable
[core-0.1.22]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.22
[tokio-rs#1862]: tokio-rs#1862
[tokio-rs#1901]: tokio-rs#1901
[tokio-rs#1903]: tokio-rs#1903
[tokio-rs#1871]: tokio-rs#1871
[tokio-rs#1890]: tokio-rs#1890
[tokio-rs#1902]: tokio-rs#1902
[tokio-rs#1893]: tokio-rs#1893
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

2 participants