bevy/crates/bevy_log/src/lib.rs
Zachary Harrold c5365509bf Allow partial support for bevy_log in no_std (#18782)
- Fixes #18781

- Moved `LogPlugin` into its own file gated behind a new `tracing`
feature.
- Used `log` instead of `tracing` where possible.
- Exposed a new `tracing` feature in `bevy` which enables
`bevy_log/tracing`.
- Gated `LogPlugin` from `DefaultPlugins` on `tracing` feature.

- CI

---

- If you were previously using `bevy_log` with default features
disabled, enable the new `std` and `tracing` features.
- If you were using `bevy` with the default features disabled, enable
the new `tracing` feature.

Almost all of the diffs in this PR come from moving `LogPlugin` into its
own file. This just makes the PR less noisy, since the alternative is
excessive `#[cfg(feature = "tracing")]` directives all over the plugin.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
2025-04-11 09:03:12 +02:00

66 lines
2.0 KiB
Rust

#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc(
html_logo_url = "https://bevyengine.org/assets/icon.png",
html_favicon_url = "https://bevyengine.org/assets/icon.png"
)]
//! This crate provides logging functions and configuration for [Bevy](https://bevyengine.org)
//! apps, and automatically configures platform specific log handlers (i.e. Wasm or Android).
//!
//! The macros provided for logging are reexported from [`tracing`](https://docs.rs/tracing),
//! and behave identically to it.
//!
//! By default, the [`LogPlugin`] from this crate is included in Bevy's `DefaultPlugins`
//! and the logging macros can be used out of the box, if used.
//!
//! For more fine-tuned control over logging behavior, set up the [`LogPlugin`] or
//! `DefaultPlugins` during app initialization.
#![cfg_attr(
not(feature = "tracing"),
doc = "\n\n[`LogPlugin`]: https://docs.rs/bevy_log"
)]
#![no_std]
#[cfg(feature = "std")]
extern crate std;
extern crate alloc;
#[cfg(all(target_os = "android", feature = "std"))]
mod android_tracing;
mod once;
#[cfg(feature = "tracing")]
mod plugin;
#[cfg(feature = "trace_tracy_memory")]
#[global_allocator]
static GLOBAL: tracy_client::ProfiledAllocator<std::alloc::System> =
tracy_client::ProfiledAllocator::new(std::alloc::System, 100);
/// The log prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
debug, debug_once, error, error_once, info, info_once, trace, trace_once, warn, warn_once,
};
#[doc(hidden)]
pub use bevy_utils::once;
#[cfg(feature = "tracing")]
#[doc(hidden)]
pub use crate::{debug_span, error_span, info_span, trace_span, warn_span};
}
pub use bevy_utils::once;
pub use log::{debug, error, info, trace, warn};
#[cfg(feature = "tracing")]
pub use {
crate::plugin::{BoxedLayer, LogPlugin, DEFAULT_FILTER},
tracing::{self, debug_span, error_span, info_span, trace_span, warn_span, Level},
tracing_subscriber,
};