Skip to content

Commit

Permalink
move once from bevy_log to bevy_utils, to allow for it's use in bevy_…
Browse files Browse the repository at this point in the history
…ecs (#11419)

# Objective

When working within `bevy_ecs`, we can't use the `log_once` macros due
to their placement in `bevy_log` - which depends on `bevy_ecs`. All this
create does is migrate those macros to the `bevy_utils` crate, while
still re-exporting them in `bevy_log`.

created to resolve this:
#11417 (comment)
  • Loading branch information
lee-orr committed Jan 19, 2024
1 parent 7125dcb commit 478a1ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
15 changes: 9 additions & 6 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
//! For more fine-tuned control over logging behavior, set up the [`LogPlugin`] or
//! `DefaultPlugins` during app initialization.

mod once;

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

Expand All @@ -31,12 +29,17 @@ pub mod prelude {
debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span,
};

pub use crate::{debug_once, error_once, info_once, trace_once, warn_once};
#[doc(hidden)]
pub use bevy_utils::{debug_once, error_once, info_once, once, trace_once, warn_once};
}

pub use bevy_utils::tracing::{
debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span,
Level,
pub use bevy_utils::{
debug_once, error_once, info_once, once, trace_once,
tracing::{
debug, debug_span, error, error_span, info, info_span, trace, trace_span, warn, warn_span,
Level,
},
warn_once,
};
pub use tracing_subscriber;

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod cow_arc;
mod default;
mod float_ord;
pub mod intern;
mod once;

pub use crate::uuid::Uuid;
pub use ahash::{AHasher, RandomState};
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_log/src/once.rs → crates/bevy_utils/src/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,52 @@ macro_rules! once {
}};
}

/// Call [`trace!`](crate::trace) once per call site.
/// Call [`trace!`](crate::tracing::trace) once per call site.
///
/// Useful for logging within systems which are called every frame.
#[macro_export]
macro_rules! trace_once {
($($arg:tt)+) => ({
$crate::once!($crate::trace!($($arg)+))
$crate::once!($crate::tracing::trace!($($arg)+))
});
}

/// Call [`debug!`](crate::debug) once per call site.
/// Call [`debug!`](crate::tracing::debug) once per call site.
///
/// Useful for logging within systems which are called every frame.
#[macro_export]
macro_rules! debug_once {
($($arg:tt)+) => ({
$crate::once!($crate::debug!($($arg)+))
$crate::once!($crate::tracing::debug!($($arg)+))
});
}

/// Call [`info!`](crate::info) once per call site.
/// Call [`info!`](crate::tracing::info) once per call site.
///
/// Useful for logging within systems which are called every frame.
#[macro_export]
macro_rules! info_once {
($($arg:tt)+) => ({
$crate::once!($crate::info!($($arg)+))
$crate::once!($crate::tracing::info!($($arg)+))
});
}

/// Call [`warn!`](crate::warn) once per call site.
/// Call [`warn!`](crate::tracing::warn) once per call site.
///
/// Useful for logging within systems which are called every frame.
#[macro_export]
macro_rules! warn_once {
($($arg:tt)+) => ({
$crate::once!($crate::warn!($($arg)+))
$crate::once!($crate::tracing::warn!($($arg)+))
});
}

/// Call [`error!`](crate::error) once per call site.
/// Call [`error!`](crate::tracing::error) once per call site.
///
/// Useful for logging within systems which are called every frame.
#[macro_export]
macro_rules! error_once {
($($arg:tt)+) => ({
$crate::once!($crate::error!($($arg)+))
$crate::once!($crate::tracing::error!($($arg)+))
});
}

0 comments on commit 478a1ef

Please sign in to comment.