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

Make tracing Optional for bevy_utils #15879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions crates/bevy_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = ["std", "serde"]
default = ["std", "serde", "tracing"]
std = [
"alloc",
"tracing/std",
"log/std",
"ahash/std",
"dep:thread_local",
"ahash/runtime-rng",
"tracing?/std",
]
alloc = ["hashbrown/default"]
tracing = ["dep:tracing"]
detailed_trace = []
serde = ["hashbrown/serde"]

[dependencies]
ahash = { version = "0.8.7", default-features = false, features = [
"compile-time-rng",
] }
tracing = { version = "0.1", default-features = false }
log = { version = "0.4", default-features = false }
tracing = { version = "0.1", default-features = false, optional = true }
hashbrown = { version = "0.14.2", default-features = false }
bevy_utils_proc_macros = { version = "0.15.0-dev", path = "macros" }
thread_local = { version = "1.0", optional = true }
Expand Down
23 changes: 13 additions & 10 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ pub use ahash::{AHasher, RandomState};
pub use bevy_utils_proc_macros::*;
pub use default::default;
pub use hashbrown;
pub use log;
#[cfg(feature = "std")]
pub use parallel_queue::*;
pub use time::*;

#[cfg(feature = "tracing")]
pub use tracing;

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -383,36 +386,36 @@ impl<F: FnOnce()> Drop for OnDrop<F> {
}
}

/// Calls the [`tracing::info!`] macro on a value.
/// Calls the [`log::info!`] macro on a value.
pub fn info<T: Debug>(data: T) {
tracing::info!("{:?}", data);
log::info!("{:?}", data);
}

/// Calls the [`tracing::debug!`] macro on a value.
/// Calls the [`log::debug!`] macro on a value.
pub fn dbg<T: Debug>(data: T) {
tracing::debug!("{:?}", data);
log::debug!("{:?}", data);
}

/// Processes a [`Result`] by calling the [`tracing::warn!`] macro in case of an [`Err`] value.
/// Processes a [`Result`] by calling the [`log::warn!`] macro in case of an [`Err`] value.
pub fn warn<E: Debug>(result: Result<(), E>) {
if let Err(warn) = result {
tracing::warn!("{:?}", warn);
log::warn!("{:?}", warn);
}
}

/// Processes a [`Result`] by calling the [`tracing::error!`] macro in case of an [`Err`] value.
/// Processes a [`Result`] by calling the [`log::error!`] macro in case of an [`Err`] value.
pub fn error<E: Debug>(result: Result<(), E>) {
if let Err(error) = result {
tracing::error!("{:?}", error);
log::error!("{:?}", error);
}
}

/// Like [`tracing::trace`], but conditional on cargo feature `detailed_trace`.
/// Like [`log::trace`], but conditional on cargo feature `detailed_trace`.
#[macro_export]
macro_rules! detailed_trace {
($($tts:tt)*) => {
if cfg!(detailed_trace) {
bevy_utils::tracing::trace!($($tts)*);
bevy_utils::log::trace!($($tts)*);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions 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::tracing::trace) once per call site.
/// Call [`trace!`](crate::log::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::tracing::trace!($($arg)+))
$crate::once!($crate::log::trace!($($arg)+))
});
}

/// Call [`debug!`](crate::tracing::debug) once per call site.
/// Call [`debug!`](crate::log::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::tracing::debug!($($arg)+))
$crate::once!($crate::log::debug!($($arg)+))
});
}

/// Call [`info!`](crate::tracing::info) once per call site.
/// Call [`info!`](crate::log::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::tracing::info!($($arg)+))
$crate::once!($crate::log::info!($($arg)+))
});
}

/// Call [`warn!`](crate::tracing::warn) once per call site.
/// Call [`warn!`](crate::log::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::tracing::warn!($($arg)+))
$crate::once!($crate::log::warn!($($arg)+))
});
}

/// Call [`error!`](crate::tracing::error) once per call site.
/// Call [`error!`](crate::log::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::tracing::error!($($arg)+))
$crate::once!($crate::log::error!($($arg)+))
});
}