Skip to content

Commit fa0745f

Browse files
authored
Remove bevy log's usage of non send resource (#13252)
# Objective I'm adopting #9122 and pulling some of the non controversial changes out to make the final pr easier to review. This pr removes the NonSend resource usage from `bevy_log`. ## Solution `tracing-chrome` uses a guard that is stored in the world, so that when it is dropped the json log file is written out. The guard is Send + !Sync, so we can store it in a SyncCell to hold it in a regular resource instead of using a non send resource. ## Testing Tested by running an example with `-F tracing chrome` and making sure there weren't any errors and the json file was created. --- ## Changelog - replaced `bevy_log`'s usage of a non send resource.
1 parent 6c78c7b commit fa0745f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/bevy_log/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ use tracing_log::LogTracer;
5454
#[cfg(feature = "tracing-chrome")]
5555
use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields};
5656
use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter};
57+
#[cfg(feature = "tracing-chrome")]
58+
use {bevy_ecs::system::Resource, bevy_utils::synccell::SyncCell};
59+
60+
/// Wrapper resource for `tracing-chrome`'s flush guard.
61+
/// When the guard is dropped the chrome log is written to file.
62+
#[cfg(feature = "tracing-chrome")]
63+
#[allow(dead_code)]
64+
#[derive(Resource)]
65+
pub(crate) struct FlushGuard(SyncCell<tracing_chrome::FlushGuard>);
5766

5867
/// Adds logging to Apps. This plugin is part of the `DefaultPlugins`. Adding
5968
/// this plugin will setup a collector appropriate to your target platform:
@@ -177,7 +186,7 @@ impl Plugin for LogPlugin {
177186
}
178187
}))
179188
.build();
180-
app.insert_non_send_resource(guard);
189+
app.insert_resource(FlushGuard(SyncCell::new(guard)));
181190
chrome_layer
182191
};
183192

0 commit comments

Comments
 (0)