Document use of NO_COLOR in LogPlugin (#13984)

# Objective
Fixes #13982

## Solution
~~Adds a new field to `bevy_log::LogPlugin`: `ansi: bool`~~
Documents the use of `std::env::set_var("NO_COLOR", "1");` to disable
colour output in terminals.

## Testing
Yes, all tests passed when I ran `cargo run -p ci -- test` and `cargo
run -p ci -- lints`

I have only tested the code on my Mac, though I doubt this change would
have any affect on other platforms.

---
This commit is contained in:
Caleb Yates 2024-06-25 07:04:55 +10:00 committed by GitHub
parent d48ebdf641
commit 82fd3df719
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -101,6 +101,21 @@ pub(crate) struct FlushGuard(SyncCell<tracing_chrome::FlushGuard>);
/// If you define the `RUST_LOG` environment variable, the [`LogPlugin`] settings
/// will be ignored.
///
/// Also, to disable colour terminal output (ANSI escape codes), you can
/// set the environment variable `NO_COLOR` to any value. This common
/// convention is documented at [no-color.org](https://no-color.org/).
/// For example:
/// ```no_run
/// # use bevy_app::{App, NoopPluginGroup as DefaultPlugins, PluginGroup};
/// # use bevy_log::LogPlugin;
/// fn main() {
/// std::env::set_var("NO_COLOR", "1");
/// App::new()
/// .add_plugins(DefaultPlugins)
/// .run();
/// }
/// ```
///
/// If you want to setup your own tracing collector, you should disable this
/// plugin from `DefaultPlugins`:
/// ```no_run
@ -218,6 +233,9 @@ impl Plugin for LogPlugin {
#[cfg(feature = "tracing-tracy")]
let tracy_layer = tracing_tracy::TracyLayer::default();
// note: the implementation of `Default` reads from the env var NO_COLOR
// to decide whether to use ANSI color codes, which is common convention
// https://no-color.org/
let fmt_layer = tracing_subscriber::fmt::Layer::default().with_writer(std::io::stderr);
// bevy_render::renderer logs a `tracy.frame_mark` event every frame