Module bevy::log::tracing_subscriber::reload
source · Expand description
Wrapper for a Layer
to allow it to be dynamically reloaded.
This module provides a Layer
type implementing the Layer
trait or Filter
trait
which wraps another type implementing the corresponding trait. This
allows the wrapped type to be replaced with another
instance of that type at runtime.
This can be used in cases where a subset of Layer
or Filter
functionality
should be dynamically reconfigured, such as when filtering directives may
change at runtime. Note that this layer introduces a (relatively small)
amount of overhead, and should thus only be used as needed.
Examples
Reloading a global filtering layer:
use tracing_subscriber::{filter, fmt, reload, prelude::*};
let filter = filter::LevelFilter::WARN;
let (filter, reload_handle) = reload::Layer::new(filter);
tracing_subscriber::registry()
.with(filter)
.with(fmt::Layer::default())
.init();
info!("This will be ignored");
reload_handle.modify(|filter| *filter = filter::LevelFilter::INFO);
info!("This will be logged");
Reloading a Filtered
layer:
use tracing_subscriber::{filter, fmt, reload, prelude::*};
let filtered_layer = fmt::Layer::default().with_filter(filter::LevelFilter::WARN);
let (filtered_layer, reload_handle) = reload::Layer::new(filtered_layer);
tracing_subscriber::registry()
.with(filtered_layer)
.init();
info!("This will be ignored");
reload_handle.modify(|layer| *layer.filter_mut() = filter::LevelFilter::INFO);
info!("This will be logged");
Note
The Layer
implementation is unable to implement downcasting functionality,
so certain Layer
will fail to downcast if wrapped in a reload::Layer
.
If you only want to be able to dynamically change the
Filter
on a layer, prefer wrapping that Filter
in the reload::Layer
.
Structs
- Indicates that an error occurred when reloading a layer.
- Allows reloading the state of an associated
Layer
. - Wraps a
Layer
orFilter
, allowing it to be reloaded dynamically at runtime.