Skip to content

Conversation

@grandizzy
Copy link
Collaborator

Summary

Adds a new cheatcode getRecordedLogsJson that returns recorded logs as a JSON string, similar to the existing getStateDiffJson pattern.

This allows users to easily post-process recorded logs externally without needing to manually transform the Log[] array to JSON.

Motivation

Closes #12854

Users heavily rely on log analysis for simulation and auditing purposes. Currently they have to use recordLogs -> custom transform to JSON -> writeJson, which is cumbersome. This cheatcode provides a native way to get recorded logs as JSON for external processing.

JSON Format

[
  {
    "topics": ["0x...", "0x..."],
    "data": "0x...",
    "emitter": "0x..."
  }
]

All binary fields are hex-encoded with 0x prefix.

Changes

  • Added getRecordedLogsJson() function declaration in vm.rs
  • Added LogJson struct for JSON serialization
  • Implemented the cheatcode following the same pattern as getStateDiffJson
  • Added tests verifying JSON structure and values

Testing

  • testRecordedLogsJson: Verifies emitter address, topics (event signature + indexed args), and hex-encoded data
  • testRecordedLogsJsonEmpty: Verifies empty logs returns []

Adds a new cheatcode `getRecordedLogsJson` that returns recorded logs
as a JSON string, similar to the existing `getStateDiffJson` pattern.

This allows users to easily post-process recorded logs externally without
needing to manually transform the Log[] array to JSON.

JSON format:
```json
[{"topics": ["0x..."], "data": "0x...", "emitter": "0x..."}]
```

Closes #12854
@grandizzy grandizzy added this pull request to the merge queue Jan 15, 2026
Merged via the queue into master with commit 6bfca30 Jan 15, 2026
16 checks passed
@grandizzy grandizzy deleted the gdzzy/get-recorded-logs-json branch January 15, 2026 10:20
@github-project-automation github-project-automation bot moved this to Done in Foundry Jan 15, 2026
@sakulstra
Copy link
Contributor

sakulstra commented Feb 3, 2026

Hey, I'm a bit confused - how can i use this on latest nightly? Do i need to wait for a release of forge-std, as it seems to not to be available yet.

@sakulstra
Copy link
Contributor

Added a pr here foundry-rs/forge-std#809 as i think it's missing (on docs it is mentioned, but seems to not exist)

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

getRecordedLogs[Json]

3 participants