Skip to content

Commit 8c92699

Browse files
Copilotj178
andauthored
Make trace command logging truncation configurable via PREK_LOG_TRUNCATE_LIMIT (#1679)
Trace-level `Executing ...` lines currently truncate command arguments at a hardcoded 120 characters, which hides critical details when debugging hooks (notably `docker_image` entrypoint/args). This change introduces a configurable truncate limit while preserving existing default behavior. - **Config surface: new env var** - Added `PREK_LOG_TRUNCATE_LIMIT` to `prek-consts` (`EnvVars`). - **Runtime behavior in command logging** - Updated `Cmd` display formatting in `crates/prek/src/process.rs` to read truncation limit from `PREK_LOG_TRUNCATE_LIMIT`. - Cached the resolved truncate limit with `LazyLock` so env parsing happens once. - Kept default at `120` when unset/invalid. - Treated `0` as invalid and fallback to default to avoid degenerate output. - **Documentation** - Added `PREK_LOG_TRUNCATE_LIMIT` to `docs/configuration.md` under environment variables, including default and intent. - **Focused unit coverage** - Added tests for: - env var value parsing (valid/invalid/zero), - env-based resolution behavior, - cached-limit behavior via `LazyLock`, - env restoration guard to avoid cross-test env leakage. ```rust const DEFAULT_COMMAND_LOG_TRUNCATE_LIMIT: usize = 120; static COMMAND_LOG_TRUNCATE_LIMIT: LazyLock<usize> = LazyLock::new(command_log_truncate_limit_from_env); fn command_log_truncate_limit() -> usize { *COMMAND_LOG_TRUNCATE_LIMIT } ``` <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Do not truncate trace run executions</issue_title> > <issue_description>### Summary > > I was trying to debug a docker_image hook execution and was delighted to note the --log-file option. > > However, turns out that the "Executing" TRACE run lines are truncated with `[...]` before showing the part I'm actually interested in (a case of tweaking entrypoints and arguments). > > I'd suggest not truncating these lines in the trace log at all, or providing an option not to truncate. > > ### Willing to submit a PR? > > - [ ] Yes — I’m willing to open a PR to fix this. > > ### Platform > > Ubuntu 25.10 amd64 > > ### Version > > 0.3.2 > > ### .pre-commit-config.yaml > > N/A > > ### Log file > > ``` > 2026-02-20T10:17:47.223740Z TRACE run{hook_id=... language=docker_image}: Executing `cd ... && docker run --rm --tty --user 1000:1000 --init --volume ...:/src:rw,Z --workdir /src --entrypoint ... --network [...]` > ```</issue_description> > > <agent_instructions>Add a new env var to prek-consts, controlling the command line log truncate limit in process.rs, current it is hardcoded to 120. Document it in docs/configuration.md env vars section.</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #1678 <!-- START COPILOT CODING AGENT TIPS --> --- 🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
1 parent 4872215 commit 8c92699

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

crates/prek-consts/src/env_vars.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl EnvVars {
2828
pub const SSL_CERT_FILE: &'static str = "SSL_CERT_FILE";
2929
pub const PREK_CONTAINER_RUNTIME: &'static str = "PREK_CONTAINER_RUNTIME";
3030
pub const PREK_QUIET: &'static str = "PREK_QUIET";
31+
pub const PREK_LOG_TRUNCATE_LIMIT: &'static str = "PREK_LOG_TRUNCATE_LIMIT";
3132

3233
// PREK internal environment variables
3334
pub const PREK_INTERNAL__TEST_DIR: &'static str = "PREK_INTERNAL__TEST_DIR";

crates/prek/src/process.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@ use std::fmt::Display;
3030
use std::path::Path;
3131
use std::process::Output;
3232
use std::process::{CommandArgs, CommandEnvs, ExitStatus, Stdio};
33+
use std::sync::LazyLock;
3334

3435
use owo_colors::OwoColorize;
36+
use prek_consts::env_vars::EnvVars;
3537
use thiserror::Error;
3638
use tracing::trace;
3739

3840
use crate::git::GIT;
3941

42+
static LOG_TRUNCATE_LIMIT: LazyLock<usize> = LazyLock::new(|| {
43+
EnvVars::var(EnvVars::PREK_LOG_TRUNCATE_LIMIT)
44+
.ok()
45+
.and_then(|limit| limit.parse::<usize>().ok())
46+
.filter(|limit| *limit > 0)
47+
.unwrap_or(120)
48+
});
49+
4050
/// An error from executing a Command
4151
#[derive(Debug, Error)]
4252
pub enum Error {
@@ -495,7 +505,7 @@ impl Display for Cmd {
495505
}
496506
write!(f, " {}", arg.to_string_lossy())?;
497507
len += arg.len() + 1;
498-
if len > 120 {
508+
if len > *LOG_TRUNCATE_LIMIT {
499509
write!(f, " [...]",)?;
500510
break;
501511
}

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,8 @@ prek supports the following environment variables:
13551355
- `podman`
13561356
- `container` (Apple's Container runtime on macOS, see [container](https://github.com/apple/container))
13571357

1358+
- `PREK_LOG_TRUNCATE_LIMIT` — Control the truncation limit for command lines shown in trace logs (`Executing ...`). Defaults to `120` characters of arguments; set a larger value to reduce truncation.
1359+
13581360
Compatibility fallbacks:
13591361

13601362
- `PRE_COMMIT_ALLOW_NO_CONFIG` — Fallback for `PREK_ALLOW_NO_CONFIG`.

0 commit comments

Comments
 (0)