# `logs`

`kix logs` builds the cluster, finds the named package's primary workload, and
replaces itself with `kubectl logs` for every pod that workload
selects. It saves looking up the namespace and label selector by hand.

This page is hand-maintained. Check `cli/kix-cli/src/cli.rs`,
`cli/kix-cli/src/commands/logs.rs`, and `cli/kix-cli/src/commands/workload.rs`
when in doubt.

## Synopsis

```text
kix logs <CLUSTER> <PACKAGE> [-f] [--tail <N>] [-c <CONTAINER>]
         [--since <DURATION>] [-p] [--context <CONTEXT>] [--flake <FLAKE>]
```

| Argument or flag | Meaning |
| --- | --- |
| `<CLUSTER>` | Cluster name to build from the flake. |
| `<PACKAGE>` | Package instance name, such as `vaultwarden`. Use `<namespace>/<name>` when the instance name appears in more than one namespace. |
| `-f`, `--follow` | Stream new lines (`kubectl logs -f`). |
| `--tail <N>` | Show only the last `N` lines of each container (`kubectl logs --tail`). Unset shows everything kubectl returns by default. |
| `-c`, `--container <NAME>` | Show one container. Without it, every container is shown. |
| `--since <DURATION>` | Only lines newer than a relative duration, such as `5m`, `2h`, or `1h30m`. |
| `-p`, `--previous` | Logs from the previous terminated container (`kubectl logs --previous`). |
| `--context <CONTEXT>` | Kubeconfig context, passed through to `kubectl`. |

`-q` suppresses the line naming the workload and selector. See
[Global flags](/docs/reference/cli/global-flags/) for `--flake` and
`--override-input`.

## Workload selection

The primary workload is the first Deployment in the package's resources, then
the first StatefulSet, then the first DaemonSet. A package with none of these
is an error. Kix passes the workload's `spec.selector.matchLabels` to
`kubectl logs -l`, together with `--all-containers=true`, `--prefix=true`, and
`--max-log-requests 20`, so every replica's output appears with a pod and
container prefix.

## Examples

<Command commands={[
  "kix logs demo web -f",
  "kix logs demo production/web --since 10m -c app",
]} />

## Exit status

On success `kix logs` is replaced by `kubectl`, so the exit status is
kubectl's. A build or package-resolution failure exits `1`.

:::tip[Use it in a task]
See [Use `kix logs`](/docs/how-to/operate-a-cluster/use-kix-logs/)
for the day-to-day workflow.
:::