Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Clarify duplicate logger error #6757

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ impl Plugin for LogPlugin {
}));
}

let finished_subscriber;
let default_filter = { format!("{},{}", self.level, self.filter) };
LogTracer::init().unwrap();
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new(&default_filter))
.unwrap();
Expand Down Expand Up @@ -166,25 +166,33 @@ impl Plugin for LogPlugin {
#[cfg(feature = "tracing-tracy")]
let subscriber = subscriber.with(tracy_layer);

bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
finished_subscriber = subscriber;
}

#[cfg(target_arch = "wasm32")]
{
console_error_panic_hook::set_once();
let subscriber = subscriber.with(tracing_wasm::WASMLayer::new(
finished_subscriber = subscriber.with(tracing_wasm::WASMLayer::new(
tracing_wasm::WASMLayerConfig::default(),
));
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
}

#[cfg(target_os = "android")]
{
let subscriber = subscriber.with(android_tracing::AndroidLayer::default());
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
finished_subscriber = subscriber.with(android_tracing::AndroidLayer::default());
}

let logger_already_set = LogTracer::init().is_err();
let subscriber_already_set =
bevy_utils::tracing::subscriber::set_global_default(finished_subscriber).is_err();

match (logger_already_set, subscriber_already_set) {
(true, true) => warn!(
"Could not set global logger and tracing subscriber as they are already set. Consider disabling LogPlugin."
),
(true, _) => warn!("Could not set global logger as it is already set. Consider disabling LogPlugin."),
(_, true) => warn!("Could not set global tracing subscriber as it is already set. Consider disabling LogPlugin."),
_ => (),
}
}
}