Fetching Canister logs dynamically or by using rs-agent

Is there is a way to fetch canister logs using ic-cdk or using agent-rs. Also is it possible right now for a canister to fetch its own logs?

1 Like

@maksym Could you kindly assist me with this matter?

hi @gravity_vi.

Is there is a way to fetch canister logs using ic-cdk or using agent-rs .

currently one can fetch logs using DFX, see examples for Rust and Motoko.

agent-rs should work fine, because DFX is using it to fetch logs, see here.

agent-js might not yet be up-to-date in regards to reading/writing log_visibility but it is going to be fixed soon.

Also is it possible right now for a canister to fetch its own logs?

no, canisters can not fetch logs as per specification:

IC method fetch_canister_logs

This method can only be called by external users via non-replicated calls, i.e., it cannot be called by canisters, as replicated calls, and from composite query calls.
2 Likes

Thank you @maksym. I have few more questions:

  1. How do we upgrade the current canisters log_visibility as ic_cdk latest version canister settings does not contain any option for the log_visibility?

  2. Our canisters have been structured such that in a subnet all the individual canisters are controlled by one canister (user_index). So that user_index is the controller of the all the existing canisters and responsible for spawning new individual canisters. Assuming there is no way for user_index to fetch logs from all the individual canisters, how can I ensure that exising canisters and as well as new canisters are maked with log_visibility as public?

For the first question: You can pin the ic_cdk version to the git rev of this PR

1 Like

After Severin’s PR is merged and released it will be possible to update canister settings and change log_visibility.

Additionally (in a more distant future) we are considering adding allowed list to log_visibility so that it’s not fully public and not strictly controllers.

Something what we should also add to our IC4J Java Agent.

Thank you @maksym and @Severin for all the help :slightly_smiling_face:

2 Likes