Feature: add --json flag for machine-readable log comparison output - #180
Open
casks-mutters wants to merge 1 commit into
Open
Feature: add --json flag for machine-readable log comparison output#180casks-mutters wants to merge 1 commit into
casks-mutters wants to merge 1 commit into
Conversation
## 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
log_audit.pycurrently 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
--jsonflag that emits a machine-readable summary of the comparison result.Changes
build_parser()inlog_audit.pywith a--jsonboolean flag.main(), aftercompare_logs(...):--jsonis not set: keep the current human-readable prints.--jsonis 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 }Rationale
Backwards compatibility
--json.