diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 62921f669f..f42f45c477 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -1,55 +1,107 @@ use bevy_app::{PluginGroup, PluginGroupBuilder}; +use bevy_app::ScheduleRunnerPlugin; +use bevy_asset::AssetPlugin; +#[cfg(feature = "bevy_audio")] +use bevy_audio::AudioPlugin; +use bevy_core::CorePlugin; +use bevy_diagnostic::DiagnosticsPlugin; +#[cfg(feature = "bevy_gilrs")] +use bevy_gilrs::GilrsPlugin; +#[cfg(feature = "bevy_gltf")] +use bevy_gltf::GltfPlugin; +use bevy_input::InputPlugin; +use bevy_log::LogPlugin; +#[cfg(feature = "bevy_pbr")] +use bevy_pbr::PbrPlugin; +#[cfg(feature = "bevy_render")] +use bevy_render::RenderPlugin; +use bevy_scene::ScenePlugin; +#[cfg(feature = "bevy_sprite")] +use bevy_sprite::SpritePlugin; +#[cfg(feature = "bevy_text")] +use bevy_text::TextPlugin; +use bevy_transform::TransformPlugin; +#[cfg(feature = "bevy_ui")] +use bevy_ui::UiPlugin; +#[cfg(feature = "bevy_wgpu")] +use bevy_wgpu::WgpuPlugin; +use bevy_window::WindowPlugin; +#[cfg(feature = "bevy_winit")] +use bevy_winit::WinitPlugin; + +/// This plugin group will add all the default plugins: +/// * [`LogPlugin`] +/// * [`CorePlugin`] +/// * [`TransformPlugin`] +/// * [`DiagnosticsPlugin`] +/// * [`InputPlugin`] +/// * [`WindowPlugin`] +/// * [`AssetPlugin`] +/// * [`ScenePlugin`] +/// * [`RenderPlugin`] - with feature `bevy_render` +/// * [`SpritePlugin`] - with feature `bevy_sprite` +/// * [`PbrPlugin`] - with feature `bevy_pbr` +/// * [`UiPlugin`] - with feature `bevy_ui` +/// * [`TextPlugin`] - with feature `bevy_text` +/// * [`AudioPlugin`] - with feature `bevy_audio` +/// * [`GilrsPlugin`] - with feature `bevy_gilrs` +/// * [`GltfPlugin`] - with feature `bevy_gltf` +/// * [`WinitPlugin`] - with feature `bevy_winit` +/// * [`WgpuPlugin`] - with feature `bevy_wgpu` pub struct DefaultPlugins; impl PluginGroup for DefaultPlugins { fn build(&mut self, group: &mut PluginGroupBuilder) { - group.add(bevy_log::LogPlugin::default()); - group.add(bevy_core::CorePlugin::default()); - group.add(bevy_transform::TransformPlugin::default()); - group.add(bevy_diagnostic::DiagnosticsPlugin::default()); - group.add(bevy_input::InputPlugin::default()); - group.add(bevy_window::WindowPlugin::default()); - group.add(bevy_asset::AssetPlugin::default()); - group.add(bevy_scene::ScenePlugin::default()); + group.add(LogPlugin::default()); + group.add(CorePlugin::default()); + group.add(TransformPlugin::default()); + group.add(DiagnosticsPlugin::default()); + group.add(InputPlugin::default()); + group.add(WindowPlugin::default()); + group.add(AssetPlugin::default()); + group.add(ScenePlugin::default()); #[cfg(feature = "bevy_render")] - group.add(bevy_render::RenderPlugin::default()); + group.add(RenderPlugin::default()); #[cfg(feature = "bevy_sprite")] - group.add(bevy_sprite::SpritePlugin::default()); + group.add(SpritePlugin::default()); #[cfg(feature = "bevy_pbr")] - group.add(bevy_pbr::PbrPlugin::default()); + group.add(PbrPlugin::default()); #[cfg(feature = "bevy_ui")] - group.add(bevy_ui::UiPlugin::default()); + group.add(UiPlugin::default()); #[cfg(feature = "bevy_text")] - group.add(bevy_text::TextPlugin::default()); + group.add(TextPlugin::default()); #[cfg(feature = "bevy_audio")] - group.add(bevy_audio::AudioPlugin::default()); + group.add(AudioPlugin::default()); #[cfg(feature = "bevy_gilrs")] - group.add(bevy_gilrs::GilrsPlugin::default()); + group.add(GilrsPlugin::default()); #[cfg(feature = "bevy_gltf")] - group.add(bevy_gltf::GltfPlugin::default()); + group.add(GltfPlugin::default()); #[cfg(feature = "bevy_winit")] - group.add(bevy_winit::WinitPlugin::default()); + group.add(WinitPlugin::default()); #[cfg(feature = "bevy_wgpu")] - group.add(bevy_wgpu::WgpuPlugin::default()); + group.add(WgpuPlugin::default()); } } +/// Minimal plugin group that will add the following plugins: +/// * [`CorePlugin`] +/// * [`ScheduleRunnerPlugin`] pub struct MinimalPlugins; impl PluginGroup for MinimalPlugins { fn build(&mut self, group: &mut PluginGroupBuilder) { - group.add(bevy_core::CorePlugin::default()); - group.add(bevy_app::ScheduleRunnerPlugin::default()); + group.add(CorePlugin::default()); + group.add(ScheduleRunnerPlugin::default()); } } diff --git a/crates/bevy_log/Cargo.toml b/crates/bevy_log/Cargo.toml index d977f800f6..e330f6ace2 100644 --- a/crates/bevy_log/Cargo.toml +++ b/crates/bevy_log/Cargo.toml @@ -26,3 +26,6 @@ android_log-sys = "0.2.0" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.6" tracing-wasm = "0.2" + +[dev-dependencies] +bevy_internal = { path = "../bevy_internal", version = "0.5.0" } diff --git a/crates/bevy_log/src/lib.rs b/crates/bevy_log/src/lib.rs index 2460afb7ae..8da75d5f92 100644 --- a/crates/bevy_log/src/lib.rs +++ b/crates/bevy_log/src/lib.rs @@ -16,13 +16,53 @@ use bevy_app::{AppBuilder, Plugin}; use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields}; use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter}; -/// Adds logging to Apps. +/// Adds logging to Apps. This plugin is part of the `DefaultPlugins`. Adding +/// this plugin will setup a collector appropriate to your target platform: +/// * Using [`tracing-subscriber`](https://crates.io/crates/tracing-subscriber) by default, +/// logging to `stdout`. +/// * Using [`android_log-sys`](https://crates.io/crates/android_log-sys) on Android, +/// logging to Android logs. +/// * Using [`tracing-wasm`](https://crates.io/crates/tracing-wasm) in WASM, logging +/// to the browser console. +/// +/// You can configure this plugin using the resource [`LogSettings`]. +/// ```no_run +/// # use bevy_internal::DefaultPlugins; +/// # use bevy_app::App; +/// # use bevy_log::LogSettings; +/// # use bevy_utils::tracing::Level; +/// fn main() { +/// App::build() +/// .insert_resource(LogSettings { +/// level: Level::DEBUG, +/// filter: "wgpu=error,bevy_render=info".to_string(), +/// }) +/// .add_plugins(DefaultPlugins) +/// .run(); +/// } +/// ``` +/// +/// Log level can also be changed using the `RUST_LOG` environment variable. +/// It has the same syntax has the field [`LogSettings::filter`], see [`EnvFilter`]. +/// +/// If you want to setup your own tracing collector, you should disable this +/// plugin from `DefaultPlugins` with [`AppBuilder::add_plugins_with`]: +/// ```no_run +/// # use bevy_internal::DefaultPlugins; +/// # use bevy_app::App; +/// # use bevy_log::LogPlugin; +/// fn main() { +/// App::build() +/// .add_plugins_with(DefaultPlugins, |group| group.disable::()) +/// .run(); +/// } +/// ``` #[derive(Default)] pub struct LogPlugin; /// LogPlugin settings pub struct LogSettings { - /// Filters logs using the [EnvFilter] format + /// Filters logs using the [`EnvFilter`] format pub filter: String, /// Filters out logs that are "less than" the given level. diff --git a/examples/2d/many_sprites.rs b/examples/2d/many_sprites.rs index a63fa9a693..c8dbc2a8cf 100644 --- a/examples/2d/many_sprites.rs +++ b/examples/2d/many_sprites.rs @@ -90,7 +90,7 @@ fn tick(time: Res