|
195 | 195 | //! Enabling test capturing comes at the expense of color and other style support |
196 | 196 | //! and may have performance implications. |
197 | 197 | //! |
198 | | -//! ## Disabling colors |
| 198 | +//! ## Colors |
199 | 199 | //! |
200 | | -//! Colors and other styles can be configured with the `RUST_LOG_STYLE` |
201 | | -//! environment variable. It accepts the following values: |
| 200 | +//! Outputting of colors and other styles can be controlled by the `RUST_LOG_STYLE` |
| 201 | +//! environment variable. It accepts the following [values][fmt::WriteStyle]: |
202 | 202 | //! |
203 | 203 | //! * `auto` (default) will attempt to print style characters, but don't force the issue. |
204 | 204 | //! If the console isn't available on Windows, or if TERM=dumb, for example, then don't print colors. |
205 | 205 | //! * `always` will always print style characters even if they aren't supported by the terminal. |
206 | 206 | //! This includes emitting ANSI colors on Windows if the console API is unavailable. |
207 | 207 | //! * `never` will never print style characters. |
208 | 208 | //! |
| 209 | +//! Color may be applied in the logged message or a [custom formatter][fmt]. |
| 210 | +//! |
| 211 | +//! <div class="warning"> |
| 212 | +//! |
| 213 | +//! Logging of untrusted inputs can cause unexpected behavior as they may include ANSI escape codes which |
| 214 | +//! will be forwarded to the users terminal as part of "Weaponizing ANSI Escape Sequences". |
| 215 | +//! |
| 216 | +//! Mitigations include: |
| 217 | +//! - Setting `RUST_LOG_STYLE=never` to have all ANSI escape codes stripped |
| 218 | +//! - In the application, calling [`Builder::write_style(Never)`] to have all ANSI escape codes stripped |
| 219 | +//! - In the application, [stripping ANSI escape codes](https://docs.rs/anstream/latest/anstream/adapter/fn.strip_str.html) |
| 220 | +//! from user inputs |
| 221 | +//! |
| 222 | +//! Note: deactivating the build-time feature `color` is not a mitigation as that removes all ANSI escape code |
| 223 | +//! stripping from `env_logger`. |
| 224 | +//! |
| 225 | +//! </div> |
| 226 | +//! |
209 | 227 | //! ## Tweaking the default format |
210 | 228 | //! |
211 | 229 | //! Parts of the default format can be excluded from the log output using the [`Builder`]. |
|
0 commit comments