Capturing debug output

When debugging DAML Scripts, whether inside of a trigger or repl, is there a way to capture debug output back to the script?

1 Like

At the moment no, debug output is just written to stdout. What you could do is to have your own wrapper that tracks debug mesasges in something like a State action in addition to printing it out. Then you can easily capture debug messages.


Is there a particularly nice way to write this in DAML, for example, how would you instrument a fetchByKey ?

1 Like

Not quite sure I’m following. So far your question was about DAML Script and triggers but fetchByKey is not something you can use there.

As for implementing it in DAML it depends on what exactly you want. A very simple solution would look something like:

newtype StateT s m a = StateT { runStateT :: s -> m (a, s) }

-- Omitted instances for Action, see

modify : Action m => (s -> s) -> StateT s m a
modify = _ --implementation omitted, see

debug' : Text -> StateS [Text] Script ()
debug' t = = do
  modify (t ::) -- Note that we prepend for efficiency, just revers the log at the end.
  debug t

You can then wrap the stuff you want to capture the output of in runStateT and capture the output.

1 Like

My apologies, I was not being clear with my original question. If I have a debug within the body of a choice, and then I run a trigger which ends up exercising that choice, is there a way to capture the output. My understanding is that you can’t. That’s why I used fetchByKey as an example.

Thanks for that code though, that is what I was looking for.

1 Like

Oh right, that’s not possible. The debug call in the choice happens on the ledger and isn’t exposed via the ledger API. You would have to capture it within the choice and for example return it via the choice argument. For capturing it within the choice you could use something similar like the above but a StateT [Text] Update.