Skip to content

Add transaction ID to Cadence log entries #466

@bartolomej

Description

@bartolomej

Issue To Be Solved

Let's say we have a transaction that uses the log() function to print something.

transaction {
  execute {
    log("Hello!")
  }
}

When that transaction is executed on the local emulator blockchain, the produced log outputs are displayed as emulator (Flow CLI) logs like so:

9:24PM INF LOG: "Hello!"
9:25PM INF LOG: "Hello!"

Problem: There is no way to tie a log entry to the transaction that emitted it. I believe this would be useful for many reasons:

  • users of Flow CLI can clearly see which logs were emitted within the same transaction (even if they can't remember the transaction ID)
    • this is especially useful in cases where each transaction emits multiple logs, which makes it harder to visually categorize them
  • developer tools using flow-emulator (e.g. Flowser, Flow playground,...) can provide a better UX
    • this would allow such tools to extract the transaction ID from each log and show it within the UI of the corresponding transaction

Suggest A Solution

We could solve this by including the transaction ID in each Cadence log entry, like so:

9:24PM INF transactionId=33d14437d6e5cb23b4d6de3b70ea754a815e2d4fac79ae85a29558da2b942aef LOG: "Hello!"
9:25PM INF transactionId=70d05c026c8c400dbd7a8627daffdd89cd3ca3d64c1fdf621275b8fd0f245833 LOG: "Hello!"

... or we could include only a subset ID to make it easier to view in the terminal:

9:24PM INF transactionId=33d14...422aef LOG: "Hello!"
9:25PM INF transactionId=70d05...45833 LOG: "Hello!"

Context

In the Flowser app, we have a logs view that shows all historic logs that ever happened (in the current emulator session). But when you execute a transaction in isolation, you usually only care about that transaction's logs and not all the historic ones.

This change would allow us to show currently executed transaction logs within that transaction's info view (related to this feature we just built: onflowser/flowser#170).

Metadata

Metadata

Labels

FeatureA new user feature or a new package APIFeedback

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions