-
Notifications
You must be signed in to change notification settings - Fork 754
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
subscriber: Add SubscriberBuilder
/Layer
accessors
#1871
Conversation
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.
There was a problem hiding this 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?
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 |
Okay, let's go ahead and get this merged, and we can rename all the field formatter APIs separately. Thanks for the PR! |
# 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
# 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
`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
`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
`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
`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
## 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
# 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
Motivation
SubscriberBuilder
s andLayer
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 totracing_subscriber::fmt()
along with accessors like.compact()
that modify the formatter.Solution
Add accessors
.map_event_format()
and.map_fmt_fields()
toSubscriberBuilder
andLayer
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 theMakeWriter
, to round out the accessors for the various type parameters.The filter type is currently restricted to just
LevelFilter
orEnvFilter
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