forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_layers.rs
47 lines (41 loc) · 1.37 KB
/
log_layers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! This example illustrates how to add custom log layers in bevy.
use bevy::{
log::tracing_subscriber::{layer::SubscriberExt, Layer},
log::BoxedSubscriber,
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());
}
}
fn update_subscriber(subscriber: BoxedSubscriber) -> BoxedSubscriber {
Box::new(subscriber.with(CustomLayer))
}
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(bevy::log::LogPlugin {
update_subscriber: Some(update_subscriber),
..default()
}))
.add_systems(Update, log_system)
.run();
}
fn log_system() {
// here is how you write new logs at each "log level" (in "most import" 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");
}