Skip to content

refactor(log): route all logs through the tracing crate - #71

Merged
pepedinho merged 1 commit into
mainfrom
refactor/logging-tracing
Sep 13, 2026
Merged

pepedinho merged 1 commit into
mainfrom
refactor/logging-tracing

Conversation

@pepedinho

Copy link
Copy Markdown
Owner

Remplac~- contrôle des logs par la crate tracing tout en préservant les fichiers par watch.

Avant

  • Logger écrit directement dans ~/.fleet/logs/{id}.log via un Arc<Mutex<File>>, chaque call site passe un &Logger en paramètre (exec_timeout, exec_background, contain_cmd/immergé dans ensure_image, runner).
  • Le code de coloration (paint_level) est dupliqué, le console warning de parser.rs écrit sur stdout.

Après

  • Nouveau file_layer.rs (trait tracing::Layer): chaque event portant un champ log_path est appendé au fichier de la watch, dans le format historique [ts] LEVEL: message avec badges ANSI (INFO/WARNING/ERROR/JOB START/END), FLEET_NO_COLOR respecté.
  • Logger devient une façade: info/warning/error/job_start/job_end émettent des events tracing portant log_path; l'API fichier (new/fetchn/path_by_id/clean/...) est conservée (TUI fleet stats + tests inchangés).
  • Le paramètre logger: &Logger est supprimé de command.rs/container.rs/runner.rs; les call sites prod utilisent tracing::info!/warn!/error! avec log_path = %ctx.log_path().display().
  • init_tracing() est toujours actif et idempotent (OnceLock + try_init): registry = file layer + stderr filtré par RUST_LOG (défaut WARN, ANSI respecte FLEET_NO_COLOR).
  • Feature debug-logs supprimée, tracing-subscriber non-optionnel.
  • Nettoyage: ExecMetrics.logger (mort), doublon Background command launched, use anyhow::Ok.

Vérification

  • cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings, cargo test --features no-tty (45 tests, --test-threads=1), cargo build --release : tout est vert.

Per-watch log files (~/.fleet/logs/{id}.log) are preserved: a custom
tracing Layer (src/log/file_layer.rs) appends every event carrying a
log_path field, keeping the historical '[ts] LEVEL: message' format
(ANSI badges honor FLEET_NO_COLOR). Logger becomes a facade emitting
tracing events; production call sites now emit tracing macros directly
and the logger plumbing was dropped from the exec signatures.

init_tracing() is now always on and idempotent (OnceLock + try_init):
a registry with the file layer plus an RUST_LOG-filtered stderr layer
(default WARN). The debug-logs cargo feature is removed and
tracing-subscriber is a regular dependency.
@pepedinho
pepedinho merged commit 382ff20 into main Sep 13, 2026
10 checks passed
@pepedinho
pepedinho deleted the refactor/logging-tracing branch September 13, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant