 64efd08e13
			
		
	
	
		64efd08e13
		
			
		
	
	
	
	
		
			
			# Objective Fixes #16104 ## Solution I removed all instances of `:?` and put them back one by one where it caused an error. I removed some bevy_utils helper functions that were only used in 2 places and don't add value. See: #11478 ## Testing CI should catch the mistakes ## Migration Guide `bevy::utils::{dbg,info,warn,error}` were removed. Use `bevy::utils::tracing::{debug,info,warn,error}` instead. --------- Co-authored-by: SpecificProtagonist <vincentjunge@posteo.net>
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //! This example illustrates how to add custom log layers in bevy.
 | |
| 
 | |
| use bevy::{
 | |
|     log::{tracing_subscriber::Layer, BoxedLayer},
 | |
|     prelude::*,
 | |
|     utils::tracing::Subscriber,
 | |
| };
 | |
| 
 | |
| struct CustomLayer;
 | |
| 
 | |
| impl<S: Subscriber> Layer<S> for CustomLayer {
 | |
|     fn on_event(
 | |
|         &self,
 | |
|         event: &bevy::utils::tracing::Event<'_>,
 | |
|         _ctx: bevy::log::tracing_subscriber::layer::Context<'_, S>,
 | |
|     ) {
 | |
|         println!("Got event!");
 | |
|         println!("  level={}", event.metadata().level());
 | |
|         println!("  target={}", event.metadata().target());
 | |
|         println!("  name={}", event.metadata().name());
 | |
|     }
 | |
| }
 | |
| 
 | |
| // We don't need App for this example, as we are just printing log information.
 | |
| // For an example that uses App, see log_layers_ecs.
 | |
| fn custom_layer(_app: &mut App) -> Option<BoxedLayer> {
 | |
|     // You can provide multiple layers like this, since Vec<Layer> is also a layer:
 | |
|     Some(Box::new(vec![
 | |
|         bevy::log::tracing_subscriber::fmt::layer()
 | |
|             .with_file(true)
 | |
|             .boxed(),
 | |
|         CustomLayer.boxed(),
 | |
|     ]))
 | |
| }
 | |
| 
 | |
| fn main() {
 | |
|     App::new()
 | |
|         .add_plugins(DefaultPlugins.set(bevy::log::LogPlugin {
 | |
|             custom_layer,
 | |
| 
 | |
|             ..default()
 | |
|         }))
 | |
|         .add_systems(Update, log_system)
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| fn log_system() {
 | |
|     // here is how you write new logs at each "log level" (in "most important" to
 | |
|     // "least important" order)
 | |
|     error!("something failed");
 | |
|     warn!("something bad happened that isn't a failure, but thats worth calling out");
 | |
|     info!("helpful information that is worth printing by default");
 | |
|     debug!("helpful for debugging");
 | |
|     trace!("very noisy");
 | |
| }
 |