Repository: bevyengine/bevy
File: crates/bevy_ecs/src/system/commands/entity_command.rs (Rust)

Code before:
pub fn move_components<B: Bundle>(target: Entity) -> impl EntityCommand {
    move |mut entity: EntityWorldMut| {
        entity.move_components::<B>(target);
    }
}

/// An [`EntityCommand`] that logs the components of an entity.
pub fn log_components() -> impl EntityCommand {
    move |entity: EntityWorldMut| {
        let name = entity.get::<Name>().map(ToString::to_string);
        let id = entity.id();
        let mut components: Vec<_> = entity
            .world()
            .inspect_entity(id)
            .expect("Entity existence is verified before an EntityCommand is executed")
            .map(|info| info.name().to_string())
            .collect();
        components.sort();

        #[cfg(not(feature = "debug"))]
        {
            let component_count = components.len();
            #[cfg(feature = "trace")]
            {
                if let Some(name) = name {
                    info!(id=?id, name=?name, ?component_count, "log_components. Enable the `default` feature to log component names.");
                } else {
                    info!(id=?id, ?component_count, "log_components. Enable the `default` feature to log component names.");
                }
            }
            #[cfg(not(feature = "trace"))]
            {
                let name = name
                    .map(|name| alloc::format!(" ({name})"))
                    .unwrap_or_default();
                info!("Entity {id}{name}: {component_count} components. Enable the `default` feature to log component names.");
            }
        }

        #[cfg(feature = "debug")]
        {
            #[cfg(feature = "trace")]
            {
                if let Some(name) = name {
                    info!(id=?id, name=?name, ?components, "log_components");
                } else {
                    info!(id=?id, ?components, "log_components");
                }
            }
            #[cfg(not(feature = "trace"))]
            {

Review comment (bug):
should all of these strings say the `debug` feature?
```suggestion
                    info!(id=?id, name=?name, ?component_count, "log_components. Enable the `debug` feature to log component names.");
```

Code after:
pub fn move_components<B: Bundle>(target: Entity) -> impl EntityCommand {
    move |mut entity: EntityWorldMut| {
        entity.move_components::<B>(target);
    }
}

/// An [`EntityCommand`] that logs the components of an entity.
pub fn log_components() -> impl EntityCommand {
    move |entity: EntityWorldMut| {
        let name = entity.get::<Name>().map(ToString::to_string);
        let id = entity.id();
        let mut components: Vec<_> = entity
            .world()
            .inspect_entity(id)
            .expect("Entity existence is verified before an EntityCommand is executed")
            .map(|info| info.name().to_string())
            .collect();
        components.sort();

        #[cfg(not(feature = "debug"))]
        {
            let component_count = components.len();
            #[cfg(feature = "trace")]
            {
                if let Some(name) = name {
                    info!(id=?id, name=?name, ?component_count, "log_components. Enable the `debug` feature to log component names.");
                } else {
                    info!(id=?id, ?component_count, "log_components. Enable the `debug` feature to log component names.");
                }
            }
            #[cfg(not(feature = "trace"))]
            {
                let name = name
                    .map(|name| alloc::format!(" ({name})"))
                    .unwrap_or_default();
                info!("Entity {id}{name}: {component_count} components. Enable the `debug` feature to log component names.");
            }
        }

        #[cfg(feature = "debug")]
        {
            #[cfg(feature = "trace")]
            {
                if let Some(name) = name {
                    info!(id=?id, name=?name, ?components, "log_components");
                } else {
                    info!(id=?id, ?components, "log_components");
                }
            }
            #[cfg(not(feature = "trace"))]
            {