Skip to content

Feature: add --json flag for machine-readable log comparison output - #180

Open
casks-mutters wants to merge 1 commit into
mainfrom
casks-mutters-patch-74
Open

Feature: add --json flag for machine-readable log comparison output#180
casks-mutters wants to merge 1 commit into
mainfrom
casks-mutters-patch-74

Conversation

@casks-mutters

Copy link
Copy Markdown
Owner

Summary

log_audit.py currently prints human-readable information about RPC A/B logs, including lengths, a Keccak root, and (if mismatch) a small diff structure. For automation (CI, monitoring scripts, dashboards) it would be useful to have a JSON output mode.

This PR adds a --json flag that emits a machine-readable summary of the comparison result.

Changes

  • Extend build_parser() in log_audit.py with a --json boolean flag.
  • In main(), after compare_logs(...):
    • If --json is not set: keep the current human-readable prints.
    • If --json is set: print a JSON object like: json { "ok": true/false, "summary": { "fromBlock": ..., "toBlock": ..., "address": "...", "topic0": "...", "lenA": ..., "lenB": ... }, "roots": { "a": "0x...", "b": "0x..." }, "diff": { ... } // only when ok=false }
  • Preserve the existing exit code semantics (0 on match, non-zero on mismatch).

Rationale

  • Enables programmatic consumers (shell scripts, services, dashboards) to use the tool easily.
  • Keeps the current UX for manual CLI users while adding an opt-in machine-readable path.

Backwards compatibility

  • No breaking changes for existing users who don't pass --json.
  • Human output remains the same as before.

## Summary

`log_audit.py` currently prints human-readable information about RPC A/B logs, including lengths, a Keccak root, and (if mismatch) a small diff structure. For automation (CI, monitoring scripts, dashboards) it would be useful to have a JSON output mode.

This PR adds a `--json` flag that emits a machine-readable summary of the comparison result.

## Changes

- Extend `build_parser()` in `log_audit.py` with a `--json` boolean flag.
- In `main()`, after `compare_logs(...)`:
  - If `--json` is **not** set: keep the current human-readable prints.
  - If `--json` **is** set: print a JSON object like:
    ```json
    {
      "ok": true/false,
      "summary": {
        "fromBlock": ...,
        "toBlock": ...,
        "address": "...",
        "topic0": "...",
        "lenA": ...,
        "lenB": ...
      },
      "roots": {
        "a": "0x...",
        "b": "0x..."
      },
      "diff": { ... }  // only when ok=false
    }
    ```
- Preserve the existing exit code semantics (0 on match, non-zero on mismatch).

## Rationale

- Enables programmatic consumers (shell scripts, services, dashboards) to use the tool easily.
- Keeps the current UX for manual CLI users while adding an opt-in machine-readable path.

## Backwards compatibility

- No breaking changes for existing users who don't pass `--json`.
- Human output remains the same as before.
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