3

I'm debugging my program and I don't know where my code is dead. So is there any way to log strings and variables to the terminal?

3 Answers 3

3

If you're using Anchor then you can start the test suite with the detach option anchor test --detach to keep the local validator running after the tests pass/fail. This is useful if you want to look up failed transaction signatures and inspect the logs before the history gets reset.

Any msg!("logs"); will be visible in the logs

You can use an explorer with your localhost rpc url http://localhost:8899 to get a decent UI

https://solana.fm/?cluster=http%253A%252F%252Flocalhost%253A8899%252F

You might need to use skipPreFlight when sending your transaction or you might fail simulation which can mask the error.

1
  • Tks for your answer but it doesn't log anything.
    – marethyu
    Jan 19, 2023 at 6:00
1

To add to the answer, which is correct, you can use the solana logs to get live logging from your local validator ie:

$ solana logs -ul TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
Streaming transaction logs mentioning TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. Confirmed commitment

And if I do spl-token create-token in a different window, this first one will show:

Transaction executed in slot 93:
  Signature: 8MYopp3pedMs4655Ka5vyT3fw3bzmKuA4rsnbhEo2r8Mq71FwMNsmw5VL9bqabsJrKMnSkbDk29wr4Rx55T6dRU
  Status: Ok
  Log Messages:
    Program 11111111111111111111111111111111 invoke [1]
    Program 11111111111111111111111111111111 success
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]
    Program log: Instruction: InitializeMint
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2919 of 400000 compute units
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
1

your Anchor logs and Solana program msg logs will be saved inside your project in a file like: .anchor/validator-1700296750844.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.