How to show debug prints when running daml script on command-line?

I was running this script with the following command

daml script --dar .daml/dist/quickstart-0.0.1.dar --script-name Main:initialize --ledger-host localhost --ledger-port 6865 --static-time

I added a line debug alice trying 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

Do you have debug alice within a choice, i.e., in an Update or in the Script part? 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.

I have it in the Script (i.e., I added the line debug alice after line 14. I have got nothing print out after running the daml script command.

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 :+1:

Can you share the full script you are using?

Sure, it was in the first post but it is not so obvious:

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.

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]

The daml version I used is 2.4.0-snapshot.20220905.10544.0.a2ea3ce6

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:

  1. Create a project based on the quickstart-java template and cd into it:
    daml new daml-script-debug --template=quickstart-java
    cd daml-script-debug
    
  2. Edit daml/Main.daml so it prints the value of alice : Party using debug:
    printf '14a\n  debug alice\n.\nw\n' | ed -s daml/Main.daml
    
  3. 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
    
  4. After seeing the above output “Canton sandbox is ready”, open a separate terminal and cd into 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
    
  5. 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 alice line after uploading the .dar to 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 the debug alice line.

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
1 Like

My bad. sorry for the false alarm. I didn’t build it again and upload the dar

2 Likes

I can confirm I can see the log after building and uploading the new dar.

3 Likes