bevy/examples/app
Periwink ded5d523bd
Improve tracing layer customization (#13159)
# Objective

- Fixes https://github.com/bevyengine/bevy/issues/12597

The current tracing customization option (the `update_subscriber` field)
was basically unusable because it provides a `dyn Subscriber` and most
layers require a `Subscriber` that also implements `for<'a>
LookupSpan<'a, Data=Data<'a>>`, so it was impossible to add a layer on
top of the `dyn Subscriber`.

This PR provides an alternative way of adding additional tracing layers
to the LogPlugin by instead creating an `Option<Layer>`.

This is enough for most situations because `Option<Layer>` and
`Vec<Layer>` both implement `Layer`.

## Solution

- Replace the `update_subscriber` field of `LogPlugin` with a
`custom_layer` field which is function pointer returning an
`Option<BoxedLayer>`
- Update the examples to showcase that this works:
  - with multiple additional layers
- with Layers that were previously problematic, such as
`bevy::log::tracing_subscriber::fmt::layer().with_file(true)` (mentioned
in the issue)
  
Note that in the example this results in duplicate logs, since we have
our own layer on top of the default `fmt_layer` added in the LogPlugin;
maybe in the future we might want to provide a single one? Or to let the
user customize the default `fmt_layer` ? I still think this change is an
improvement upon the previous solution, which was basically broken.

---

## Changelog

> This section is optional. If this was a trivial fix, or has no
externally-visible impact, you can delete this section.

- The `LogPlugin`'s `update_subscriber` field has been replaced with
`custom_layer` to allow the user to flexibly add a `tracing::Layer` to
the layer stack

## Migration Guide

- The `LogPlugin`'s `update_subscriber` field has been replaced with
`custom_layer`

---------

Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
2024-05-12 21:16:56 +00:00
..
custom_loop.rs Fix custom_loop example to include plugin finalization (#13215) 2024-05-03 20:12:27 +00:00
drag_and_drop.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
empty.rs Doc/module style doc blocks for examples (#4438) 2022-05-16 13:53:20 +00:00
empty_defaults.rs Doc/module style doc blocks for examples (#4438) 2022-05-16 13:53:20 +00:00
headless.rs Fix intra-doc link warnings (#10445) 2023-11-08 14:33:46 +00:00
headless_renderer.rs Headless renderer example has been added (#13006) 2024-05-08 14:26:26 +00:00
log_layers.rs Improve tracing layer customization (#13159) 2024-05-12 21:16:56 +00:00
log_layers_ecs.rs Improve tracing layer customization (#13159) 2024-05-12 21:16:56 +00:00
logs.rs chore: fix some comments (#13083) 2024-04-25 19:09:16 +00:00
no_renderer.rs Add configuration for async pipeline creation on RenderPlugin (#11847) 2024-02-16 13:35:47 +00:00
plugin.rs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
plugin_group.rs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
return_after_run.rs Remove redundant imports (#12817) 2024-04-01 19:59:08 +00:00
thread_pool_resources.rs Break CorePlugin into TaskPoolPlugin, TypeRegistrationPlugin, FrameCountPlugin. (#7083) 2023-01-05 11:42:35 +00:00
without_winit.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00