Skip to content

Add machine-readable (JSON) log output to all CLI tools#57

Draft
sjoerdsimons with Copilot wants to merge 3 commits into
mainfrom
copilot/add-json-formatted-log-output
Draft

Add machine-readable (JSON) log output to all CLI tools#57
sjoerdsimons with Copilot wants to merge 3 commits into
mainfrom
copilot/add-json-formatted-log-output

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown

All CLI binaries only supported human-readable log output, with no way to consume logs programmatically.

Changes

  • {aptlyctl,apt2aptly,obs2aptly,aptly-latest-snapshots}/Cargo.toml: enable the json feature for tracing-subscriber
  • Each binary's main.rs:
    • Add LogFormat enum (pretty | json) with clap::ValueEnum
    • Add --log-format to Opts
    • Extract subscriber initialization into a local fn init_tracing(LogFormat) helper
    • Fix initialization order to Opts::parse()init_tracing()color_eyre::install() so ErrorLayer is registered before color-eyre's hook runs
  • aptlyctl/src/repo.rs: fix pre-existing clippy::useless_conversion warning

Usage

aptlyctl --log-format json snapshot list
obs2aptly --log-format json my-repo ./obs-packages

JSON output uses tracing-subscriber's built-in JSON formatter; pretty (the default) preserves existing behavior.

Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 15:09
Copilot AI linked an issue Jul 7, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot July 7, 2026 15:17
Copilot AI changed the title [WIP] Add machine-readable log output in JSON format Add machine-readable (JSON) log output to all CLI tools Jul 7, 2026
Copilot AI requested a review from sjoerdsimons July 7, 2026 15:24
@sjoerdsimons
sjoerdsimons force-pushed the copilot/add-json-formatted-log-output branch from ece0bed to dd05896 Compare July 16, 2026 07:44
@sjoerdsimons

Copy link
Copy Markdown
Contributor

@andrewshadura tagging you in as this is a fixed for an issue you filed ;)

Comment thread apt2aptly/src/main.rs Outdated

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

Adds a new --log-format {pretty,json} CLI option across all binaries so logs can be consumed programmatically (JSON) while preserving existing human-readable output (pretty). This fits the codebase by standardizing tracing initialization across the CLI tools and enabling tracing-subscriber’s JSON formatter consistently.

Changes:

  • Enable tracing-subscriber’s json feature in each binary crate.
  • Add LogFormat + --log-format and refactor tracing subscriber setup into init_tracing(...) in each main.rs.
  • Adjust startup order to parse CLI args before initializing tracing, then install color-eyre (plus a small clippy warning fix in aptlyctl/src/repo.rs).

Reviewed changes

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

Show a summary per file
File Description
obs2aptly/src/main.rs Adds --log-format and initializes tracing via init_tracing(LogFormat).
obs2aptly/Cargo.toml Enables tracing-subscriber JSON support for machine-readable logs.
aptlyctl/src/main.rs Adds --log-format and refactors subscriber initialization into init_tracing.
aptlyctl/Cargo.toml Enables tracing-subscriber JSON support.
aptlyctl/src/repo.rs Fixes a pre-existing clippy warning (clippy::useless_conversion).
aptly-latest-snapshots/src/main.rs Adds --log-format and moves tracing init after Opts::parse().
aptly-latest-snapshots/Cargo.toml Enables tracing-subscriber JSON support.
apt2aptly/src/main.rs Adds --log-format and refactors subscriber initialization into init_tracing.
apt2aptly/Cargo.toml Enables tracing-subscriber JSON support.
Cargo.lock Adds dependencies required by tracing-subscriber JSON feature (serde_json, tracing-serde, etc.).

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

Comment thread obs2aptly/src/main.rs Outdated
Comment thread aptlyctl/src/main.rs Outdated
#[clap(long, env = "APTLY_API_TOKEN")]
api_token: Option<String>,
/// Log output format
#[clap(long, default_value = "pretty")]
Comment thread aptly-latest-snapshots/src/main.rs Outdated
Comment thread apt2aptly/src/main.rs Outdated
#[clap(short = 'n', long, default_value_t = false)]
dry_run: bool,
/// Log output format
#[clap(long, default_value = "pretty")]
@sjoerdsimons

Copy link
Copy Markdown
Contributor

@copilot please fix the review comments and rebase on the latest main if needed

Copilot AI requested review from Copilot and removed request for Copilot July 16, 2026 13:42

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Author

@copilot please fix the review comments and rebase on the latest main if needed

Fixed in b86dab4. I addressed the review feedback, verified the branch is not behind main, and reran cargo fmt --all --check, cargo clippy --all-targets -- -D warnings, and cargo test --all-targets --all-features.

Copilot AI review requested due to automatic review settings July 16, 2026 13:54
@sjoerdsimons
sjoerdsimons force-pushed the copilot/add-json-formatted-log-output branch from b86dab4 to d3864c0 Compare July 16, 2026 13:54

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 8 out of 9 changed files in this pull request and generated no new comments.

@andrewshadura
andrewshadura force-pushed the copilot/add-json-formatted-log-output branch from d3864c0 to 5428b4d Compare July 16, 2026 16:26
Copilot AI review requested due to automatic review settings July 16, 2026 16:26

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 8 out of 9 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 16, 2026 16:31
@andrewshadura
andrewshadura force-pushed the copilot/add-json-formatted-log-output branch from 5428b4d to 0a245c2 Compare July 16, 2026 16:31

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 8 out of 9 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Machine-readable log output

4 participants