nmbrs_runtime/debug_env.rs
1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! Developer debug switches read from `NMBRS_DEBUG_*`-style env
5//! vars.
6//!
7//! Each switch is a boolean env flag ([`nmbrs_workload::boolean`]):
8//! unset or `false` is off, `true` is on. A value that isn't a
9//! boolean leaves the switch off and logs a warning naming the
10//! canonical spelling, so `NMBRS_DEBUG_WIRES=1` never looks like it
11//! worked.
12
13/// Read the debug switch `name` once. Callers on hot paths cache the
14/// result in a `OnceLock`.
15pub fn debug_flag(name: &str) -> bool {
16 nmbrs_workload::boolean::env_flag(name).unwrap_or_else(|e| {
17 crate::diag!(
18 crate::observer::LogLevel::Warn,
19 "{e}; debug switch {name} stays off"
20 );
21 false
22 })
23}