> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# nsc logs

Print the logs for a instance and its workload.

`logs` prints logs for an instance and its workload to the standard output. It
also allows to print real-time logs or logs for the specific period.

**Note**: Printing logs is only supported for Kubernetes instances.

## Usage

```bash theme={null}
nsc logs [instance-id] [-n <namespace>] [-p <pod>] [-c <container>] [-k <kind>] [--match_message_regex <regex>] [--since <duration>] [--after <timestamp>] [--before <timestamp>] [--limit <count>] [-f] [--raw] [-o <plain|json>] [-s <source>] [--all]
```

### Example

The following example shows how to print logs for `kube-system` Kubernetes
namespace:

<Steps titleSize="h4">
  <Step title="Create an ephemeral instance">
    Create an ephemeral instance and note its ID:

    ```bash theme={null}
    nsc create
    ```

    ```text nocopy Output theme={null}
    Created instance "1lf2ol9ioulce"
     deadline: 2023-04-25T13:24:53Z
    ```
  </Step>

  <Step title="Print Kubernetes logs">
    Print logs for the `kube-system` Kubernetes namespace:

    ```bash theme={null}
    nsc logs 1lf2ol9ioulce -n kube-system
    ```
  </Step>

  <Step title="Stream Kubernetes logs">
    Stream logs for the `kube-system` Kubernetes namespace:

    ```bash theme={null}
    nsc logs 1lf2ol9ioulce -n kube-system -f
    ```
  </Step>
</Steps>

## Options

<h3 id="--namespace--n-namespace">
  \--namespace, -n \<namespace>
</h3>

If provided `nsc` prints logs only for the specified Kubernetes namespace.

<h3 id="--pod--p-pod">
  \--pod, -p \<pod>
</h3>

If provided `nsc` prints logs only for the specified Kubernetes pod. If there
are multiple pods are running with the same name (e.g. in different Kubernetes
namespaces) logs of all pods would be printed. Use in combination with `-n` flag
to print the logs for the specific pod.

<h3 id="--container--c-container">
  \--container, -c \<container>
</h3>

If provided `nsc` prints logs only for the specified container in a Kubernetes
pod. If there are multiple containers with the same name (e.g. running in
different Kubernetes pods and/or namespaces) logs of all containers would be
printed. Use in combination with `-n` and/or `-p` flag to print the logs for
the specific container.

<h3 id="--kind--k-kind">
  \--kind, -k \<kind>
</h3>

If specified, `nsc` only prints logs of the given kinds, e.g. `kubernetes`,
`containers`, `system`, or `applications`. The flag can be repeated
(`-k kubernetes -k system`) or given a comma-separated list
(`-k kubernetes,system`) to select more than one kind.

<h3 id="--match_message_regex-regex">
  \--match\_message\_regex \<regex>
</h3>

If specified, `nsc` only prints log lines whose message matches this regular
expression.

<h3 id="--since-duration">
  \--since \<duration>
</h3>

To show logs relative to a timestamp (e.g. 42m for 42 minutes). The flag can't
be used with `-f`.

<h3 id="--after-timestamp">
  \--after \<timestamp>
</h3>

Only show logs recorded after this timestamp, formatted as RFC3339 (e.g.
`2024-01-15T10:30:00Z`). Combine with `--all` to query logs across all of your
instances rather than a single one.

<h3 id="--before-timestamp">
  \--before \<timestamp>
</h3>

Only show logs recorded before this timestamp, formatted as RFC3339 (e.g.
`2024-01-15T12:00:00Z`). Combine with `--all` to query logs across all of your
instances rather than a single one.

<h3 id="--limit-count">
  \--limit \<count>
</h3>

The maximum number of log lines to return. Defaults to `1000`.

<h3 id="--follow--f">
  \--follow, -f
</h3>

If specified logs would be streamed continuously starting from now.

<h3 id="--raw">
  \--raw
</h3>

Can be specified to print raw logs - e.g. without namespace/pod/container
labels.

<h3 id="--output--o-plainjson">
  \--output, -o \<plain|json>
</h3>

Specifies the output format. Supported values are `plain` and `json`; `json`
output prints one JSON object per line. Defaults to `plain`.

<h3 id="--source">
  \--source
</h3>

If specified, display logs from this source. Default: `kubernetes`. Valid options: `kubernetes` or `containerd`

<h3 id="--all">
  \--all
</h3>

Search across all instances instead of a single instance. Requires `--since`, `--after`, or `--before` to bound the query.
