# `npx @sanity/cli functions logs`

Fetch, stream, or delete logs for one deployed Function. Always provide the Function name; omitting it only prints valid names and command help.

Run from the Blueprint directory or a subdirectory; the manifest supplies the valid Function names.

## Fetch logs

Prefer a bounded, structured query for agent work:

```sh
npx @sanity/cli functions logs process-order --limit 100 --json
```

`--limit` defaults to 50. Entries without both a level and a message are dropped, so a returned count can be lower than the limit even when more logs exist.

When entries are found, the JSON result contains a `logs` array of `{time, requestId, level, message}`. Human-readable output drops `requestId` and prints local timestamps unless `--utc` is passed. Pass `--stack NAME_OR_ID` to override the locally configured Stack.

Logs may contain payload data or application secrets. Summarize only what is needed and do not reproduce credentials or personal data.

## Stream logs

`--watch` (alias `--follow`, `-w`) keeps running until interrupted and emits human-readable output:

```sh
npx @sanity/cli functions logs process-order --watch
```

`--watch` cannot be combined with `--json`. Streamed timestamps are always UTC, so `--utc` is ignored. Use watch mode only when continuous monitoring is requested, and stop it when monitoring is complete.

## Delete logs

Deleting removes all logs for the Function. Obtain explicit authorization and confirm the Function and Stack first:

```sh
npx @sanity/cli functions logs process-order --delete
```

The command prompts (defaulting to no) unless `--force` is supplied, and `--force` requires `--delete`. Use `--force` only for an authorized non-interactive deletion. `--delete` is rejected alongside `--limit` or `--json`.
