2022-05-16 13:53:20 +00:00
|
|
|
//! This example illustrates how to use logs in bevy.
|
|
|
|
|
2020-11-13 01:23:57 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
Use plugin setup for resource only used at setup time (#6360)
# Objective
- Build on #6336 for more plugin configurations
## Solution
- `LogSettings`, `ImageSettings` and `DefaultTaskPoolOptions` are now plugins settings rather than resources
---
## Changelog
- `LogSettings` plugin settings have been move to `LogPlugin`, `ImageSettings` to `ImagePlugin` and `DefaultTaskPoolOptions` to `CorePlugin`
## Migration Guide
The `LogSettings` settings have been moved from a resource to `LogPlugin` configuration:
```rust
// Old (Bevy 0.8)
app
.insert_resource(LogSettings {
level: Level::DEBUG,
filter: "wgpu=error,bevy_render=info,bevy_ecs=trace".to_string(),
})
.add_plugins(DefaultPlugins)
// New (Bevy 0.9)
app.add_plugins(DefaultPlugins.set(LogPlugin {
level: Level::DEBUG,
filter: "wgpu=error,bevy_render=info,bevy_ecs=trace".to_string(),
}))
```
The `ImageSettings` settings have been moved from a resource to `ImagePlugin` configuration:
```rust
// Old (Bevy 0.8)
app
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins)
// New (Bevy 0.9)
app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
```
The `DefaultTaskPoolOptions` settings have been moved from a resource to `CorePlugin::task_pool_options`:
```rust
// Old (Bevy 0.8)
app
.insert_resource(DefaultTaskPoolOptions::with_num_threads(4))
.add_plugins(DefaultPlugins)
// New (Bevy 0.9)
app.add_plugins(DefaultPlugins.set(CorePlugin {
task_pool_options: TaskPoolOptions::with_num_threads(4),
}))
```
2022-10-25 22:19:34 +00:00
|
|
|
.add_plugins(DefaultPlugins.set(bevy::log::LogPlugin {
|
|
|
|
// Uncomment this to override the default log settings:
|
|
|
|
// level: bevy::log::Level::TRACE,
|
|
|
|
// filter: "wgpu=warn,bevy_ecs=info".to_string(),
|
|
|
|
..default()
|
|
|
|
}))
|
2021-07-27 23:42:36 +00:00
|
|
|
.add_system(log_system)
|
2020-11-13 01:23:57 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_system() {
|
2021-03-11 00:27:30 +00:00
|
|
|
// here is how you write new logs at each "log level" (in "least important" to "most important"
|
|
|
|
// order)
|
2020-11-13 01:23:57 +00:00
|
|
|
trace!("very noisy");
|
|
|
|
debug!("helpful for debugging");
|
|
|
|
info!("helpful information that is worth printing by default");
|
|
|
|
warn!("something bad happened that isn't a failure, but thats worth calling out");
|
|
|
|
error!("something failed");
|
|
|
|
|
|
|
|
// by default, trace and debug logs are ignored because they are "noisy"
|
Use plugin setup for resource only used at setup time (#6360)
# Objective
- Build on #6336 for more plugin configurations
## Solution
- `LogSettings`, `ImageSettings` and `DefaultTaskPoolOptions` are now plugins settings rather than resources
---
## Changelog
- `LogSettings` plugin settings have been move to `LogPlugin`, `ImageSettings` to `ImagePlugin` and `DefaultTaskPoolOptions` to `CorePlugin`
## Migration Guide
The `LogSettings` settings have been moved from a resource to `LogPlugin` configuration:
```rust
// Old (Bevy 0.8)
app
.insert_resource(LogSettings {
level: Level::DEBUG,
filter: "wgpu=error,bevy_render=info,bevy_ecs=trace".to_string(),
})
.add_plugins(DefaultPlugins)
// New (Bevy 0.9)
app.add_plugins(DefaultPlugins.set(LogPlugin {
level: Level::DEBUG,
filter: "wgpu=error,bevy_render=info,bevy_ecs=trace".to_string(),
}))
```
The `ImageSettings` settings have been moved from a resource to `ImagePlugin` configuration:
```rust
// Old (Bevy 0.8)
app
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins)
// New (Bevy 0.9)
app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
```
The `DefaultTaskPoolOptions` settings have been moved from a resource to `CorePlugin::task_pool_options`:
```rust
// Old (Bevy 0.8)
app
.insert_resource(DefaultTaskPoolOptions::with_num_threads(4))
.add_plugins(DefaultPlugins)
// New (Bevy 0.9)
app.add_plugins(DefaultPlugins.set(CorePlugin {
task_pool_options: TaskPoolOptions::with_num_threads(4),
}))
```
2022-10-25 22:19:34 +00:00
|
|
|
// you can control what level is logged by setting up the LogPlugin
|
2020-11-13 01:23:57 +00:00
|
|
|
// alternatively you can set the log level via the RUST_LOG=LEVEL environment variable
|
|
|
|
// ex: RUST_LOG=trace, RUST_LOG=info,bevy_ecs=warn
|
|
|
|
// the format used here is super flexible. check out this documentation for more info:
|
|
|
|
// https://docs.rs/tracing-subscriber/*/tracing_subscriber/filter/struct.EnvFilter.html
|
|
|
|
}
|