foundry-rs / foundry-rs/foundry

feat(anvil): display logs during the execution progress

Open
#5,352 4 comments 2 reactions 0 assignees View on GitHub
A-compatibility C-anvil T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
16h 38m
Merged PRs (30d)
511

Description

### Component

Anvil

### Describe the feature you would like

Support for console2/console.log logging in Anvil is somewhat limited and works differently than in a hardhat node, in that the logs are apparently collected in LogCollector but not available for output "inline" with other output sent to the terminal while Anvil executes contract code. This make it challenging to debug timing issues between Anvil and connected programs by observing what parts of which contracts have executed via instrumenting those contracts with `console.log()` calls in Solidity.

I've already implemented the necessary changes in sketch form. I'm just now picking up Rust, and am quite unfamiliar with the internals of Anvil/Foundry/Revm. The implementation I came up with may therefore be quite bad, but please have a look. I took this approach, vs collecting all of the logs on a per `spawn()` or `TransactionExecutor` / `next()` (I'm speaking loosely) basis so that the output from Anvil is happening in "real time"

Among other things there may be a better name than `inline-logs` for this option. Anyway, by supplying `--inline-logs` Anvil sets up a callback in the revm `Inspector` via `with_inline_logs()`, which I did that way to avoid breaking encapsulation relative to the availability of the `decode_console_log()` function. Again, there may be better ways, please educate me/suggest and I can re-implement.

See https://github.com/aathan/foundry/tree/inline_logs

EDIT: Looking even further into this, I think the eventual "correct" implementation may be to use the trace crate, and/or follow the same output mechanisms that currently emit the rest of what's going to the terminal/console. The main point here is to cause these logs to become available "inline" with other status output of the EVM execution environment, and in "real time."

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.