How to show debug prints when running daml script on command-line?
- chunlokling-da1OP
I was running this script with the following command
github.comdigital-asset/daml/blob/0c08c1cb01315fd5fe684a1ff5c67d944c2e29d3/docs/source/app-dev/bindings-java/quickstart/template-root/daml/Main.daml#L14
- module Main where
- import Daml.Script
- import Iou
- import IouTrade()
- initialize : Script [Party]
- initialize = do
- -- allocate parties
- alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
- bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
- usBank <- allocatePartyWithHint "USD_Bank" (PartyIdHint "USD_Bank")
- eurBank <- allocatePartyWithHint "EUR_Bank" (PartyIdHint "EUR_Bank")
- aliceId <- validateUserId "alice"
- bobId <- validateUserId "bob"
- eurBankId <- validateUserId "eur"
- usBankId <- validateUserId "us"
- createUser (User aliceId (Some alice)) [CanActAs alice]
- createUser (User bobId (Some bob)) [CanActAs bob]
- createUser (User eurBankId (Some eurBank)) [CanActAs eurBank]
daml script --dar .daml/dist/quickstart-0.0.1.dar --script-name Main:initialize --ledger-host localhost --ledger-port 6865 --static-timeI added a line
debug alicetrying to print the party alice but it doesn’t appear after executing the above command. I wonder if I need to change the log level or anything I have missed. Thanks - cocreature
Do you have
debug alicewithin a choice, i.e., in anUpdateor in theScriptpart? The latter should get printed. If you have it in a choice however, that code is executed in the ledger not by the script runner so you need to look at the ledger logs. It should be logged at debug level iirc. - chunlokling-da1
I have it in the Script (i.e., I added the line
debug aliceafter line 14. I have got nothing print out after running thedaml scriptcommand.I have found a --output-file argument for me to work around this. it will export the result to the output file which also solves my problem

- cocreature
Can you share the full script you are using?
- chunlokling-da1
Sure, it was in the first post but it is not so obvious:
github.comdigital-asset/daml/blob/0c08c1cb01315fd5fe684a1ff5c67d944c2e29d3/docs/source/app-dev/bindings-java/quickstart/template-root/daml/Main.daml#L14
- module Main where
- import Daml.Script
- import Iou
- import IouTrade()
- initialize : Script [Party]
- initialize = do
- -- allocate parties
- alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
- bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
- usBank <- allocatePartyWithHint "USD_Bank" (PartyIdHint "USD_Bank")
- eurBank <- allocatePartyWithHint "EUR_Bank" (PartyIdHint "EUR_Bank")
- aliceId <- validateUserId "alice"
- bobId <- validateUserId "bob"
- eurBankId <- validateUserId "eur"
- usBankId <- validateUserId "us"
- createUser (User aliceId (Some alice)) [CanActAs alice]
- createUser (User bobId (Some bob)) [CanActAs bob]
- createUser (User eurBankId (Some eurBank)) [CanActAs eurBank]
- cocreature
Can you share the version that includes your debug call? I know you said line 14 but just trying to make sure we’re looking at the same thing.
- chunlokling-da1
yeah sure thing!
initialize : Script [Party] initialize = do -- allocate parties alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice") debug alice bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob") usBank <- allocatePartyWithHint "USD_Bank" (PartyIdHint "USD_Bank") eurBank <- allocatePartyWithHint "EUR_Bank" (PartyIdHint "EUR_Bank") aliceId <- validateUserId "alice" bobId <- validateUserId "bob" eurBankId <- validateUserId "eur" usBankId <- validateUserId "us" createUser (User aliceId (Some alice)) [CanActAs alice] createUser (User bobId (Some bob)) [CanActAs bob] createUser (User eurBankId (Some eurBank)) [CanActAs eurBank] - chunlokling-da1
The daml version I used is 2.4.0-snapshot.20220905.10544.0.a2ea3ce6
- akrmn 1
Hi @chunlokling-da1. I’m trying to reproduce this issue on my machine, but I do get the expected debug output. These are the steps I’m following, please let me know if they differ from yours to help diagnose the issue:
- Create a project based on the
quickstart-javatemplate andcdinto it:daml new daml-script-debug --template=quickstart-java cd daml-script-debug - Edit
daml/Main.damlso it prints the value ofalice : Partyusingdebug:printf '14a\n debug alice\n.\nw\n' | ed -s daml/Main.daml - Build the dar, start the sandbox and upload dar to it:
daml build daml sandbox --port 6865 --dar=.daml/dist/quickstart-0.0.1.dar - After seeing the above output “Canton sandbox is ready”, open a separate terminal and
cdinto the same directory, then run the script:daml script --dar .daml/dist/quickstart-0.0.1.dar --script-name Main:initialize --ledger-host localhost --ledger-port 6865 --static-time - In my case, I see the above outputs:
[DA.Internal.Prelude:555]: 'Alice::122051b18906d25c9b896bd8eb25795aa5f0e6e244a7d7fe8c868cf07a4f3d35818c'
My first guess of what’s happening here is that you added the
debug aliceline after uploading the.darto the ledger, in which case it would make sense that the debug output is missing, since the copy of the script available to the ledger would be the one in the uploaded dar, without thedebug aliceline.EDIT: I tested this on the following SDK versions, all with the expected output:
- 2.4.0
- 2.4.0-snapshot.20220905.10544.0.a2ea3ce6
- 2.5.0-snapshot.20221028.10865.0.1b726fe8
- Create a project based on the
- chunlokling-da1 2
akrmn:daml script --dar .daml/dist/quickstart-0.0.1.dar --script-name Main:initialize --ledger-host localhost --ledger-port 6865 --static-time
My bad. sorry for the false alarm. I didn’t build it again and upload the dar
-
- chunlokling-da1 3
I can confirm I can see the log after building and uploading the new dar.