Logging | Algorand Developer Portal

Logging

Algorand Python provides a log method that allows you to emit debugging and event information as well as return values from your contracts to the caller.

This log method is a superset of the AVM log method that adds extra functionality:

Logged values are available to the calling client and attached to the transaction record stored on the blockchain ledger.

If you want to emit ARC-28 events in the logs then there is a purpose-built function for that.

Here’s an example contract that uses the log method in various ways:

from algopy import BigUInt, Bytes, Contract, log, op

class MyContract(Contract):

def approval_program(self) -> bool:

log(0)

log(b"1")

log("2")

log(op.Txn.num_app_args + 3)

log(Bytes(b"4") if op.Txn.num_app_args else Bytes())

log(

b"5",

6,

op.Txn.num_app_args + 7,

BigUInt(8),

Bytes(b"9") if op.Txn.num_app_args else Bytes(),

sep="_",

)

return True

def clear_state_program(self) -> bool:

return True