How to implement an efficient logging system in a Rust-based ICP canister without relying on heartbeat?

On the Internet Computer using Rust, and I’m trying to implement a persistent logging mechanism. I’ve come across the ic-logger project, which looks great, but it’s written in Motoko. My project is Rust-based, so I can’t use it directly.

Here’s what I’m trying to achieve:

  1. I want to store logs persistently inside a canister.
  2. I don’t want to make every function async just to perform inter-canister log transfers.
  3. I don’t want to use heartbeat either, as it consumes too many cycles.
  4. My goal is to buffer logs locally and then send them to a dedicated logging canister based on certain conditions (e.g. number of logs, specific events, or a manual flush).
  5. Are there any existing Rust-based examples or repositories that implement this kind of buffered logging pattern efficiently?
  6. Is there any guidance on how to handle stable storage for logs, especially when pruning older logs?

I just saw someone mention canlog that was just published. If you want to use the system-provided logging capabilities then that’s probably a great solution

6 Likes

You should check out this

It depend if you want logs, thats exposed and then you have to use external web2 solution (like loki) to store all the logs to long term.
If you want a solution to store forever datas as transactions on the IC, then @frederico02 is right and you should use icrc3 lib we’ve just released. Its designed for that use case.