Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print event logs in a formatted way #1776

Closed
Aviksaikat opened this issue Dec 16, 2023 · 3 comments · Fixed by #2161
Closed

Print event logs in a formatted way #1776

Aviksaikat opened this issue Dec 16, 2023 · 3 comments · Fixed by #2161
Labels
category: feature New feature or request

Comments

@Aviksaikat
Copy link
Contributor

Overview

Thanks to salparadi at discord for providing the following code.

from rich.tree import Tree
from rich.text import Text
from rich import print as rich_print
from ape.utils.trace import TraceStyles
            
def add_event_to_tree(event, tree: Tree):
    contract = ape.chain.contracts.get(event.contract_address)
    contract_name = getattr(contract, 'name', None)
    contract_address_styled = Text(event.contract_address, style="#D17706 italic")
    
    if contract_name:
        contract_name_styled = Text(contract_name, style=TraceStyles.CONTRACTS)
        contract_tree = tree.add(contract_name_styled + ' ' + contract_address_styled)
    else:
        contract_tree = tree.add(contract_address_styled)

    event_name_styled = Text(event.event_name)
    event_tree = contract_tree.add(event_name_styled)

    event_arguments = event.event_arguments.items()
    for arg, value in event_arguments:
        if isinstance(value, bytes):
            value = value.hex()
        
        event_arg_styled = Text(arg)
        event_value_styled = Text(str(value), style=TraceStyles.VALUE)
        event_tree.add(event_arg_styled + ': ' + event_value_styled)

tree = Tree("Transaction Events for " + tx.txn_hash)

for event in tx.events:
    add_event_to_tree(event, tree)

rich_print(tree)

Dependencies

  • Rich
@Aviksaikat Aviksaikat added the category: feature New feature or request label Dec 16, 2023
Copy link

linear bot commented Dec 16, 2023

@fubuloubu
Copy link
Member

this could probably be added to ReceiptAPI.show_trace()

@antazoey
Copy link
Member

this could probably be added to ReceiptAPI.show_trace()

we need to adjust evm-trace so that events show up in the right spot in the call tree.
also we have this tracked here #834

for this issue, we could add a receipts.show_events() method or something...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants