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] - log spans on panic when trace is enabled #3848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
categories = ["game-engines", "graphics", "gui", "rendering"]

[features]
trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_render/trace" ]
trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_log/trace", "bevy_render/trace" ]
trace_chrome = [ "bevy_log/tracing-chrome" ]
trace_tracy = [ "bevy_log/tracing-tracy" ]
wgpu_trace = ["bevy_render/wgpu_trace"]
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
trace = [ "tracing-error" ]

[dependencies]
bevy_app = { path = "../bevy_app", version = "0.6.0" }
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }
Expand All @@ -16,6 +19,7 @@ tracing-subscriber = {version = "0.3.1", features = ["registry", "env-filter"]}
tracing-chrome = { version = "0.4.0", optional = true }
tracing-tracy = { version = "0.8.0", optional = true }
tracing-log = "0.1.2"
tracing-error = { version = "0.2.0", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
android_log-sys = "0.2.0"
Expand Down
16 changes: 16 additions & 0 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
//! For more fine-tuned control over logging behavior, insert a [`LogSettings`] resource before
//! adding [`LogPlugin`] or `DefaultPlugins` during app initialization.

#[cfg(feature = "trace")]
use std::panic;

#[cfg(target_os = "android")]
mod android_tracing;

Expand All @@ -21,6 +24,7 @@ pub mod prelude {
debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span,
};
}

pub use bevy_utils::tracing::{
debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span,
Level,
Expand Down Expand Up @@ -105,6 +109,15 @@ impl Default for LogSettings {

impl Plugin for LogPlugin {
fn build(&self, app: &mut App) {
#[cfg(feature = "trace")]
{
let old_handler = panic::take_hook();
panic::set_hook(Box::new(move |infos| {
println!("{}", tracing_error::SpanTrace::capture());
old_handler(infos);
}));
}

let default_filter = {
let settings = app.world.get_resource_or_insert_with(LogSettings::default);
format!("{},{}", settings.level, settings.filter)
Expand All @@ -115,6 +128,9 @@ impl Plugin for LogPlugin {
.unwrap();
let subscriber = Registry::default().with(filter_layer);

#[cfg(feature = "trace")]
let subscriber = subscriber.with(tracing_error::ErrorLayer::default());

#[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))]
{
#[cfg(feature = "tracing-chrome")]
Expand Down