Skip to content

Conversation

janhohenheim
Copy link
Member

@janhohenheim janhohenheim commented Oct 17, 2025

Objective

log_components looks like this:
image

eek! what is going on??? I could pretty-print this by fiddling with the logging filters, but that

  • is weird boilerplate, just arcane enough that I would not be able to do it without looking it up or copy-pasting it from somewhere and
  • would change ALL debug prints to use newlines, which would flood my terminal.

Can I just pretty print the component log plz?

Solution

Add log_components_pretty:

image

much better!

  • The name and the entity ID of the logged entity
  • All component names without the DebugName wrapper
  • Alphanumerically sorted components

And we can go one step further when downstream (thanks Chris!)

DefaultPlugins.set(bevy::log::LogPlugin {
            fmt_layer: |_| {
                Some(Box::new(
                    bevy::log::tracing_subscriber::fmt::Layer::default()
                        .map_fmt_fields(|f| f.debug_alt())
                        .with_writer(std::io::stderr),
                ))
            },
            ..default()
        })

which gives us newlines:

image

Additional info

Added a debug feature because the experience of getting blasted with 30 strings telling me to enable a feature is suboptimal.

@janhohenheim janhohenheim added A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Dev-Tools Tools used to debug Bevy applications. D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 17, 2025
@ChristopherBiscardi
Copy link
Contributor

The alternative is to use the logging infrastructure to do this.

fn fmt_layer(
    _app: &mut App,
) -> Option<bevy::log::BoxedFmtLayer> {
    Some(Box::new(
        bevy::log::tracing_subscriber::fmt::Layer::default()
        .map_fmt_fields(|f| f.debug_alt())
        .with_writer(std::io::stderr),
    ))
}
.add_plugins(DefaultPlugins.set(bevy::log::LogPlugin {
    fmt_layer,
    ..default()
}))

and log_components upstream should really be:

pub fn log_components() -> impl EntityCommand {
    move |entity: EntityWorldMut| {
        let debug_infos: Vec<_> = entity
            .world()
            .inspect_entity(entity.id())
            .expect("Entity existence is verified before an EntityCommand is executed")
            .map(bevy::ecs::component::ComponentInfo::name)
            .collect();
        info!(
            entity=?entity.id(),
            names=?debug_infos,
            "log_components"
        );
    }
}

which results in:

screenshot-2025-10-17-at-15 58 54@2x

DebugName's Debug format probably also shouldn't print DebugName{ name: x }

@ChristopherBiscardi
Copy link
Contributor

also 0.17 regressed the output here by introducing DebugName. The 0.16 output used to be just the strings:

screenshot-2025-10-17-at-16 28 32@2x

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, but I'd prefer to only have one method for this. I'm fine to either make this the only method, or to require users to provide an argument to log_components.

@janhohenheim
Copy link
Member Author

janhohenheim commented Oct 17, 2025

I did not know that the alt debugger was different from pretty printing! Tried it out and it's lovely. Changed it to Chris' suggestion :)

Not updating the screenshots since it looks basically the same as my original PR.
Updated screenshots!

@alice-i-cecile alice-i-cecile added the C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. label Oct 17, 2025
.inspect_entity(entity.id())
.expect("Entity existence is verified before an EntityCommand is executed")
.map(ComponentInfo::name)
.map(|info| info.name().to_string())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just leaving a note here that this isn't as_string because as_string only exists on debug whereas to_string handles the debug/no-debug difference

@Lyndon-Mackay
Copy link
Contributor

I don’t want to block this, but something to consider is being able to put these in a span as my default logging settings tend to block info level logs from sources other then my game.

If I could put an optional span name it would be easier to just allow a specific span name.

Even if you don’t use span for filtering it could be another way of pinning down the specific log?

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 18, 2025
@Lyndon-Mackay
Copy link
Contributor

I don’t want to block this, but something to consider is being able to put these in a span as my default logging settings tend to block info level logs from sources other then my game.

If I could put an optional span name it would be easier to just allow a specific span name.

Even if you don’t use span for filtering it could be another way of pinning down the specific log?

I think it is best to defer to another request, as discussed in discord

auto-merge was automatically disabled October 18, 2025 04:06

Head branch was pushed to by a user without write access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dev-Tools Tools used to debug Bevy applications. A-Diagnostics Logging, crash handling, error reporting and performance analysis C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants