Logs from your code
The canister logs the Internet Computer keeps are small and rotate quickly. Sending logs from your code gives you structured, searchable lines that last as long as you choose, and that link to traces.
-
Turn on Logs in your Agent, under Telemetry › Data connections, if it isn’t on yet.
-
Add your canister as a sender. On the Logs connection, open Senders and choose Add a sender. The review grants your canister permission to write logs. It needs an Admin of the Agent.
-
Add the client to your canister. The sender’s guide shows the exact code for your canister. For Motoko it starts like this:
import Logs "mo:lumera-client";let logs = Logs.init(1);Logs.bindProducer(logs, Principal.toBlob(Principal.fromActor(this)));ignore Logs.emit(logs, "payments-api started", null);A Rust client,
lumera-ic-client, does the same. -
Deploy, then check. The sender reads Receiving once its first lines arrive. Find them in Explore logs.
Good to know
Section titled “Good to know”- Writing a log line is synchronous and cheap. The client sends lines in batches when you flush.
- Include the trace ID when you have one, and the line gets an Open trace link.
- Never log secrets or personal data: anyone who can read the Agent’s logs can read them.
- The client libraries come from the icLens source and aren’t on Mops or crates.io yet. The sender guide shows where to get them.