Skip to main content

Via API

After you invoke an action, you can stream the invocation’s logs in real time:
import Kernel from '@onkernel/sdk';

const kernel = new Kernel();

const logs = await kernel.invocations.follow(invocation_id);
Log lines will be truncated to 64KiB. For large payloads write data to external storage and log a reference instead.

Example

Here’s an example showing how to handle streaming logs:
Typescript/Javascript
const follow = await kernel.invocations.follow(invocation.id);

for await (const evt of follow) {
  if (evt.event === 'log') {
    console.log(`[${evt.timestamp}] ${evt.message}`);
  } else if (evt.event === 'error') {
    console.error('Error:', evt.error.message);
    break;
  } else if (evt.event === 'invocation_state') {
    if (evt.invocation.status === 'succeeded' || evt.invocation.status === 'failed') {
      break;
    }
  }
}

Via CLI

You can also stream the logs to your terminal via the CLI:
kernel logs <app_name> --follow
If you don’t specify --follow, the logs will print to the terminal until 3 seconds of inactivity and then stops. You can get logs for a specific invocation by adding:
-i --invocation <invocation id>    Show logs for a specific invocation of the app.