Add UV_LOG_CONTEXT to EnvironmentOptions (#16031)

## Summary
Add UV_LOG_CONTEXT to EnvironmentOptions
Relates https://github.com/astral-sh/uv/issues/14720

## Test Plan

Tests with existing tests
This commit is contained in:
Andrei Berenda 2025-09-26 01:01:29 +04:00 committed by GitHub
parent 372283c0cf
commit 1d76c5a365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 1 deletions

View File

@ -571,6 +571,7 @@ pub struct EnvironmentOptions {
pub python_install_bin: Option<bool>,
pub python_install_registry: Option<bool>,
pub install_mirrors: PythonInstallMirrors,
pub log_context: Option<bool>,
}
impl EnvironmentOptions {
@ -592,6 +593,7 @@ impl EnvironmentOptions {
EnvVars::UV_PYTHON_DOWNLOADS_JSON_URL,
)?,
},
log_context: parse_boolish_environment_variable(EnvVars::UV_LOG_CONTEXT)?,
})
}
}

View File

@ -367,6 +367,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
},
durations_layer,
globals.color,
environment.log_context.unwrap_or_default(),
)?;
// Configure the `Printer`, which controls user-facing output in the CLI.

View File

@ -14,6 +14,7 @@ use tracing_tree::time::Uptime;
use uv_cli::ColorChoice;
use uv_logging::UvFormat;
#[cfg(feature = "tracing-durations-export")]
use uv_static::EnvVars;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
@ -35,6 +36,7 @@ pub(crate) fn setup_logging(
level: Level,
durations_layer: Option<impl Layer<Registry> + Send + Sync>,
color: ColorChoice,
detailed_logging: bool,
) -> anyhow::Result<()> {
// We use directives here to ensure `RUST_LOG` can override them
let default_directive = match level {
@ -87,7 +89,6 @@ pub(crate) fn setup_logging(
};
let writer = std::sync::Mutex::new(anstream::AutoStream::new(std::io::stderr(), color_choice));
let detailed_logging = std::env::var(EnvVars::UV_LOG_CONTEXT).is_ok();
if detailed_logging {
// Regardless of the tracing level, include the uptime and target for each message.
tracing_subscriber::registry()