Skip to content

feat(configuration): add configurable trace style and rename threshold to trace_filter - #2037

Merged
josecelano merged 15 commits into
torrust:developfrom
josecelano:889-logging-style
Jul 28, 2026
Merged

josecelano merged 15 commits into
torrust:developfrom
josecelano:889-logging-style

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Make the tracing logging style configurable from the configuration file. Replace the hardcoded TraceStyle::Default with a user-selectable option, and rename threshold to trace_filter for clarity and consistency with tracing crate terminology.

Closes #889

Changes

  • Redesigned TraceStyle enum: Renamed Default → Full, simplified Pretty(bool) → Pretty (dropped display_filename boolean parameter)
  • New config fields:
    • trace_filter (renamed from threshold) — filtering level for tracing output
    • trace_style — configurable output style: full (default), pretty, compact, json
  • Updated v3 configuration to use the new logging options
  • Documentation updates: issue spec progress, migration guide references, epic restructuring

Config example

[logging]
trace_filter = "info"
trace_style = "full"

Verification

Manual verification is deferred to #1980.

josecelano and others added 11 commits July 28, 2026 18:13
…d to trace_filter

- Rename `threshold` to `trace_filter` in v3 `Logging` struct (level-only Threshold retained)
- Add `trace_style` field with four unit variants: full, pretty, compact, json
- Default trace style is `full` (backward-compatible behaviour)
- Redesign TraceStyle enum: rename Default→Full, drop Pretty(bool)→Pretty
- Add negative test: v3 Logging rejects the removed `threshold` key
- Update v3 generated default config and all v3 test fixtures
- Update issue torrust#889 spec and EPIC torrust#1978 status to IN_REVIEW

Co-authored-by: josecelano <[email protected]>
…st#1980

Add T8 to torrust#1980 implementation plan: run torrust#889 manual verification scenarios
(M1-M5) after consumer migration. These scenarios require the tracker to
use v3 config, which is not possible until this cleanup migrates global
callers.
- Move epic spec from standalone file to folder type: 1978-configuration-overhaul-epic/EPIC.md
- Add migration-guide.md with skeleton and completed sections (torrust#889, torrust#1640, torrust#1981, torrust#1417, torrust#1136)
- Add explicit TODOs for pending subissues (torrust#1490, torrust#1987, torrust#1980, torrust#2023) with reasons
- Update all 7 references across open/closed issue specs, AGENTS.md, and PR reviews
Update 7 files that referenced the old standalone epic path
to use the new folder-based path (1978-configuration-overhaul-epic/EPIC.md).
Added a subtask to all 12 EPIC torrust#1978 subissues reminding implementers to
update the migration guide if the subissue affects the configuration public API.
Also added this as step 4 in the EPIC's default completion policy.
- Updated progress log with PR-ready status
- Marked manual verification as deferred to torrust#1980 (final cleanup)
- Updated workflow checkpoints
Copilot AI review requested due to automatic review settings July 28, 2026 18:05
@josecelano
josecelano requested a review from a team as a code owner July 28, 2026 18:05
@josecelano josecelano self-assigned this Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the configuration v3.0.0 logging schema to make the tracing output style configurable via TOML, aligning naming with tracing terminology by renaming threshold to trace_filter. It also updates multiple EPIC/issue docs to reflect the ongoing configuration-overhaul restructuring and introduces a v2→v3 migration guide.

Changes:

  • Add [logging].trace_style (full/pretty/compact/json) and rename [logging].threshold → trace_filter in the v3 schema, wiring both into tracing initialization.
  • Extend/adjust v3 configuration tests and add focused unit tests for trace-style deserialization + rejecting the removed threshold key.
  • Documentation restructuring: EPIC path updates and a new configuration-v2-to-v3-migration.md guide.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/configuration/src/v3_0_0/mod.rs Updates v3 config examples + mandatory-option validation key from logging.threshold to logging.trace_filter; adjusts fixtures/tests accordingly.
packages/configuration/src/v3_0_0/logging.rs Implements configurable trace_style, renames threshold to trace_filter, and adds unit tests for style parsing and legacy-key rejection.
docs/pr-reviews/pr-2021-copilot-suggestions.md Updates tracked references to match EPIC spec path changes.
docs/issues/open/AGENTS.md Updates examples to reflect EPIC specs living under .../EPIC.md.
docs/issues/open/889-1978-new-config-option-for-logging-style.md Marks #889 implementation tasks complete and documents scope decisions.
docs/issues/open/2023-1978-expose-configured-public-urls-in-runtime-observability.md Adds “update migration guide” task to the plan.
docs/issues/open/1987-add-config-option-to-use-ip-from-announce-query-string/ISSUE.md Updates EPIC link path and adds “update migration guide” task.
docs/issues/open/1980-1978-configuration-overhaul-final-cleanup.md Adds deferred manual verification tasks for #889 to #1980 plan.
docs/issues/open/1978-configuration-overhaul-epic/EPIC.md Updates EPIC metadata/spec path, adds migration-guide link, and updates #889 status.
docs/issues/open/1978-configuration-overhaul-epic/configuration-v2-to-v3-migration.md New migration guide documenting v2→v3 breaking changes and TODO sections for pending subissues.
docs/issues/open/1490-1978-decompose-database-config-and-overhaul-secrets.md Adds “update migration guide” task to the plan.
docs/issues/open/1453-1978-ip-bans-reset-interval-configurable/ISSUE.md Adds “update migration guide” task completion entry.
docs/issues/open/1415-1978-use-service-binding-instead-of-socket-addr/ISSUE.md Adds “update migration guide” task completion entry.
docs/issues/open/1136-1978-configurable-udp-connection-id-validation-policy.md Updates EPIC link path and adds “update migration guide” task completion entry.
docs/issues/closed/1985-rename-peer-addr-to-ip-in-http-announce-request/ISSUE.md Updates EPIC link path.
docs/issues/closed/1981-1978-fix-tsl-config-tls-config-typo.md Updates EPIC link path and adds “update migration guide” task completion entry.
docs/issues/closed/1979-1978-copy-configuration-schema-v2-to-v3-baseline.md Adds “update migration guide” task completion entry.
docs/issues/closed/1640-1978-per-http-tracker-on-reverse-proxy-setting.md Adds “update migration guide” task completion entry.
docs/issues/closed/1417-1978-add-public-service-url-to-configuration.md Adds “update migration guide” task completion entry.
.github/skills/dev/planning/write-markdown-docs/SKILL.md Adds filename-convention guidance for Markdown docs and issue/EPIC specs.
Comments suppressed due to low confidence (4)

packages/configuration/src/v3_0_0/logging.rs:20

  • The doc comment lists Off, Error, etc., but Threshold uses #[serde(rename_all = "lowercase")], so the actual TOML values are lowercase (e.g. "info"). Align the comment with the real config values to avoid confusing users.
    /// Trace filter level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
    /// `Debug` and `Trace`. Default is `Info`.

.github/skills/dev/planning/write-markdown-docs/SKILL.md:113

  • The filename-convention table has a couple of misleading examples: it uses 889-.../ISSUE.md even though #889 is currently a standalone spec file, and it marks README as "lowercase". Using an actual folder-based issue spec example and marking README as UPPERCASE would make this table accurate and consistent with the surrounding text.
| Category       | Convention | Example                                                 |
| -------------- | ---------- | ------------------------------------------------------- |
| Templates      | UPPERCASE  | `.github/ISSUE_TEMPLATE/BUG_REPORT.md`                  |
| Issue spec     | UPPERCASE  | `1978-configuration-overhaul-epic/EPIC.md`              |
| Issue spec     | UPPERCASE  | `889-1978-new-config-option-for-logging-style/ISSUE.md` |

docs/issues/open/1978-configuration-overhaul-epic/configuration-v2-to-v3-migration.md:47

  • This sentence suggests the tracker already rejects non-3.0.0 configs, but the same document later notes v2 compatibility is retained until #1980. It would be clearer to qualify this as the post-#1980 behavior when the runtime switches to v3 by default.
The tracker will reject configs with a schema version other than `3.0.0`.

docs/issues/open/1978-configuration-overhaul-epic/configuration-v2-to-v3-migration.md:160

  • The note says omitting trace_filter falls back to the default info, but the v3 loader treats logging.trace_filter as a mandatory option (it errors if not provided). The doc should reflect that trace_filter must be present in a v3 config file.
> **Breaking**: The old `threshold` key is rejected by v3. If you omit
> `trace_filter`, the default is `info`.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/issues/open/AGENTS.md Resolved
@codecov

codecov Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.54930% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.52%. Comparing base (1731994) to head (dec5bd8).

Files with missing lines Patch % Lines
packages/configuration/src/v3_0_0/logging.rs 87.50% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2037      +/-   ##
===========================================
+ Coverage    81.46%   81.52%   +0.05%     
===========================================
  Files          344      344              
  Lines        24601    24645      +44     
  Branches     24601    24645      +44     
===========================================
+ Hits         20041    20091      +50     
+ Misses        4252     4246       -6     
  Partials       308      308              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings July 28, 2026 18:26
@josecelano

Copy link
Copy Markdown
Member Author

ACK dec5bd8

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (6)

packages/configuration/src/v3_0_0/logging.rs:16

  • #[allow(clippy::struct_excessive_bools)] is now redundant (the Logging struct has no boolean fields). Keeping unnecessary clippy suppressions makes it easier to miss real lint findings later; please remove it.
#[allow(clippy::struct_excessive_bools)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]

packages/configuration/src/v3_0_0/logging.rs:26

  • Similarly, trace_style is deserialized as lowercase strings; documenting the default/value as full (and listing supported values) is less ambiguous than Full.
    /// Trace output style. Default is `Full`.
    #[serde(default = "Logging::default_trace_style")]
    pub trace_style: TraceStyle,

packages/configuration/src/v3_0_0/logging.rs:22

  • The doc comment lists Threshold values as Off, Error, ... but the enum is deserialized with #[serde(rename_all = "lowercase")], so config values should be documented as lowercase (matching the TOML examples).

This issue also appears on line 24 of the same file.

    /// Trace filter level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
    /// `Debug` and `Trace`. Default is `Info`.
    #[serde(default = "Logging::default_trace_filter")]
    pub trace_filter: Threshold,

packages/configuration/src/v3_0_0/logging.rs:124

  • The display string uses "Json" rather than the conventional all-caps acronym "JSON".
            TraceStyle::Json => "Json Format",

.github/skills/dev/planning/write-markdown-docs/SKILL.md:117

  • The filename-conventions table mixes EPIC and issue examples, and references a folder-based 889-.../ISSUE.md that doesn't exist (this issue spec is currently the single-file docs/issues/open/889-1978-new-config-option-for-logging-style.md). Updating the examples to reflect both EPIC specs and both issue-spec layouts would avoid confusing contributors.
| Issue spec     | UPPERCASE  | `1978-configuration-overhaul-epic/EPIC.md`              |
| Issue spec     | UPPERCASE  | `889-1978-new-config-option-for-logging-style/ISSUE.md` |
| Supporting doc | lowercase  | `1978-configuration-overhaul-epic/migration-guide.md`   |

docs/issues/open/1978-configuration-overhaul-epic/configuration-v2-to-v3-migration.md:27

  • The migration guide quick-reference marks #889 as DONE, but the EPIC currently tracks it as IN_REVIEW (docs/issues/open/1978-configuration-overhaul-epic/EPIC.md:97). Consider aligning the status here so readers don't assume the change is already merged/released.
| No logging style option     | `[logging] trace_style`                                          | #889     | DONE      |
| `threshold`                 | `trace_filter`                                                   | #889     | DONE      |

@josecelano
josecelano merged commit a0c1985 into torrust:develop Jul 28, 2026
18 checks passed

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a post-merge review of #2037 as it stands at e170b9620 on the default branch.

What still runs: the v3 [logging] table carries trace_filter (the renamed level, still the Threshold enum) and trace_style (full, pretty, compact or json, default full), both in packages/configuration/src/v3_0_0/logging.rs:17-26. setup (logging.rs:65-75) passes the configured style to tracing_init (logging.rs:88-102), and logging.trace_filter is one of the mandatory options (packages/configuration/src/v3_0_0/mod.rs:441-447). The running tracker reaches this code through src/bootstrap/app.rs:79; that wiring arrived with 547f848, because at merge the binary still loaded the v2 schema with its hard-coded default style. The lines added here are unchanged at the tip apart from const fn and Self:: edits.

[Minor] tracing_init builds the subscriber with .with_test_writer() (packages/configuration/src/v3_0_0/logging.rs:92), so every event reaches stdout through print!, and print! panics when the write fails, where a plain stdout writer hands the error back and only that line is lost. With trace_style = "json" piped into a log collector, once the collector exits the next write returns EPIPE (the Rust runtime ignores SIGPIPE), and from then on every thread or task that emits an event at or above trace_filter panics instead of the tracker merely losing its log output; stdout redirected to a file on a full disk (ENOSPC) behaves the same. The line predates this change (cce0aba), but this change sends the new json style, which the migration guide offers for log aggregation, through it. Smallest fix: replace .with_test_writer() with .with_writer(std::io::stdout) in this production function; the test helper in packages/test-helpers/src/logging.rs installs its own writer and is unaffected.

[Minor] Configuration::load runs check_mandatory_options (packages/configuration/src/v3_0_0/mod.rs:400) and the full extraction (mod.rs:409) before it compares metadata.schema_version (mod.rs:412). Since the mandatory key became logging.trace_filter (mod.rs:444), a v2 file (schema_version = "2.0.0" with [logging] threshold = "info") is rejected with Missing mandatory configuration option. Option path: logging.trace_filter rather than Unsupported configuration version: 2.0.0, which asks the operator to add one key instead of migrating the file. A v2 file still in the tree shows it when loaded through TORRUST_TRACKER_CONFIG_TOML_PATH: contrib/dev-tools/experiments/dual-stack-sockets/config/tracker.dual-stack.toml:4 and :7. The test meant to cover this, v3_configuration_should_reject_schema_version_2_0_0 (mod.rs:1710-1736), had its fixture switched from threshold to trace_filter in this change and asserts only is_err(), so it no longer loads a v2-shaped file and does not check which error comes back. Smallest fix: compare metadata.schema_version (read with figment.extract_inner) before check_mandatory_options, and let the test keep threshold and match Error::UnsupportedVersion.

[Nit] The field docs name Rust variants where the file format takes lowercase strings: packages/configuration/src/v3_0_0/logging.rs:18-19 lists Off to Trace and line 23 gives the default as Full, but rename_all = "lowercase" (lines 48 and 105) rejects trace_filter = "Info" and trace_style = "Full". Listing "off" to "trace" and "full", "pretty", "compact", "json" fixes it; the Threshold variant docs (lines 50-61) also say "security level" where severity level is meant.

[Nit] packages/configuration/src/logging.rs is no longer compiled (packages/configuration/src/lib.rs:9-12 has declared no logging module since 547f848) but still holds the pre-#2037 TraceStyle with Default and Pretty(bool) and a setup hard-coded to TraceStyle::Default (line 32). A reader looking for the logging setup finds two diverging copies; deleting the file removes the stale one.

Checked and found sound: the serde wiring of both fields (defaults info and full, deny_unknown_fields rejecting a leftover threshold beside trace_filter, unknown style names rejected), the early return for off, the single call_once initialisation, the generic environment override that also covers logging.trace_style, every shipped configuration under share/default/config/ (all carry trace_filter and trace_style), and the unit tests for each style, the defaults and the filter mapping.

This branch was previously deployed

1 inactive deployment
coverage — dec5bd8a Deployed Jul 28, 2026 by josecelano via Generate Coverage Report #1722
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.

New config option for logging style

3 participants