Make Plugin::{build, setup} take &mut self instead of &self#8101
Make Plugin::{build, setup} take &mut self instead of &self#8101geieredgar wants to merge 1 commit intobevyengine:mainfrom
Plugin::{build, setup} take &mut self instead of &self#8101Conversation
alice-i-cecile
left a comment
There was a problem hiding this comment.
I'm on board with this: this isn't the first time I've seen users trip over this.
Code change itself is nearly trivial.
|
note this potentially goes would go against cart's comment here that plugin build should be stateless.
|
|
Yeah I think we should hold this line for now until we have the editor situation sorted out (and maybe also hot code reloading). The wins we get here don't outweigh the cost of trying to put this genie back in the bottle across the ecosystem. Anything that requires "state consumption" can use ECS resources for now. We can reopen (or likely re-implement) if after we've sorted everything out we decide we can do this. |
# Objective Adopted bevyengine#3778. This pr allows to configure how the bevy log is formatted. The default bevy log can be a bit verbose for some projects, specially the timestamp. The objective is to allow developers to select the format that best suits them. ``` Example of original bevy log: 2023-04-13T14:19:53.674653Z INFO bevy_render::renderer: [important text!] ``` ## Solution Using `tracing_subscriber::fmt::Subscriber`, adds the attribute `layer` to `LogPlugin`. This allows to pass a `tracing_subscriber::fmt::Layer` when creating the plugin and modifying the output. For example this ```rust App::new() .add_plugins(DefaultPlugins.set(bevy::log::LogPlugin { layer: Box::new(|| Box::new(bevy::log::tracing_subscriber::fmt::layer().pretty().without_time())) ..default() })) .run() ``` prints ``` INFO bevy_render::renderer: [important text!] ``` The main idea comes from @SonicZentropy and their pull request bevyengine#3778, but it was stale since may. This has all the changes and a fix since now `LogSettings` are included in the plugin and not in a resource. Since plugin builders are stateless and not mutable (bevyengine#8101), the old solution of using an `Option<Box<Layer>>` no longer works. One solution to fix this is to use a `Box<Fn() -> Box<Layer>>`. I am unaware of another more idiomatic fix, so if you have something better please revise it. Should plugins builders be mutable in the future, this can be changed back to the original approach. --- ## Changelog - Adds field `layer` to `LogPlugin` that takes a function returning a `tracing_subscriber` custom layer. - Reexports `tracing_subscriber` from log so it can be used to configure the plugin. - Modifies the `logs.rs` and `system_piping.rs` examples to include the new configuration. ## Migration Guide No breaking changes
# Objective Adopted bevyengine#3778. This pr allows to configure how the bevy log is formatted. The default bevy log can be a bit verbose for some projects, specially the timestamp. The objective is to allow developers to select the format that best suits them. ``` Example of original bevy log: 2023-04-13T14:19:53.674653Z INFO bevy_render::renderer: [important text!] ``` ## Solution Using `tracing_subscriber::fmt::Subscriber`, adds the attribute `layer` to `LogPlugin`. This allows to pass a `tracing_subscriber::fmt::Layer` when creating the plugin and modifying the output. For example this ```rust App::new() .add_plugins(DefaultPlugins.set(bevy::log::LogPlugin { layer: Box::new(|| Box::new(bevy::log::tracing_subscriber::fmt::layer().pretty().without_time())) ..default() })) .run() ``` prints ``` INFO bevy_render::renderer: [important text!] ``` The main idea comes from @SonicZentropy and their pull request bevyengine#3778, but it was stale since may. This has all the changes and a fix since now `LogSettings` are included in the plugin and not in a resource. Since plugin builders are stateless and not mutable (bevyengine#8101), the old solution of using an `Option<Box<Layer>>` no longer works. One solution to fix this is to use a `Box<Fn() -> Box<Layer>>`. I am unaware of another more idiomatic fix, so if you have something better please revise it. Should plugins builders be mutable in the future, this can be changed back to the original approach. --- ## Changelog - Adds field `layer` to `LogPlugin` that takes a function returning a `tracing_subscriber` custom layer. - Reexports `tracing_subscriber` from log so it can be used to configure the plugin. - Modifies the `logs.rs` and `system_piping.rs` examples to include the new configuration. ## Migration Guide No breaking changes
Objective
Pluginsto mutate themselves duringbuildandsetup.PlugintoAppeasier.Solution
Plugin::buildandPlugin::setupto take&mut selfinstead of&self.Changelog
Changed
Plugin::buildandPlugin::setupnow take&mut selfinstead of&self.Migration Guide
Pluginneed to change theirbuildandsetupimplementations to take&mut selfinstead of&self.