<a id="cloud-logs-cli"></a>

# Fetch Logs with the Confluent CLI

Use the `confluent logs` commands to fetch logs for a Confluent Cloud resource from
one place. Every log source, such as cluster health events or connector logs,
uses the same commands, flags, and output formats.

## Requirements

- The [OrganizationAdmin](../security/access-control/rbac/predefined-rbac-roles.md#organizationadmin-role) or
  [EnvironmentAdmin](../security/access-control/rbac/predefined-rbac-roles.md#environmentadmin-role) role.
- A log source for your resource. Each log source works with one resource type:

  | Log source       | Resource      | Resource ID          |
  |------------------|---------------|----------------------|
  | `cluster-health` | Kafka cluster | `lkc-` ID            |
  | `connector-logs` | Connector     | `lcc-` or `clcc-` ID |

## List log sources

To list the log sources you can query, run:

```bash
confluent logs source list
```

Your output should resemble:

```text
       Name      |     Display Name      | Resource  | ID Prefix | Lookback
-----------------+-----------------------+-----------+-----------+---------
  cluster-health | Cluster health events | kafka     | lkc       | 7d
  connector-logs | Connector logs        | connector | lcc, clcc | 3d
```

## Describe a log source

To see the search fields, allowed values, and returned fields for a log source,
run `confluent logs source describe` with the source name:

```bash
confluent logs source describe cluster-health
```

The output lists the resource type, how far back you can query, whether
`--search-text` is supported, each search field with its allowed values, and
each field that a log record returns. Add `-o json` or `-o yaml` to read the
same details in a script.

## Fetch logs

To fetch logs, run `confluent logs fetch` with the resource ID and the
`--source` flag:

```text
confluent logs fetch <resource-id> --source <log-source> [flags]
```

The `--source` flag is required. The command checks the source against the
resource ID and returns an error that names the fix when they don’t match.

The command accepts these flags:

| Flag             | Description                                                                                                                            |
|------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| `--source`       | The log source to query, such as `cluster-health`. Required.                                                                           |
| `--since`        | A relative time window that ends now, such as `1h`, `24h`, or<br/>`7d`. Don’t use it with `--from` or `--to`.                          |
| `--from`         | The start of the time window, in UTC, such as<br/>`2026-12-01T00:00:00Z`.                                                              |
| `--to`           | The end of the time window, in UTC. Defaults to now when you set<br/>`--from`.                                                         |
| `--search`       | A `field=value` filter. Repeat a field to match either value. Run<br/>`confluent logs source describe` to see the fields for a source. |
| `--search-text`  | Text to search for in log messages, for log sources that support it.                                                                   |
| `--tail`         | Return only the most recent entries, up to 1,000.                                                                                      |
| `--next`         | Fetch the next page of the previous identical query.                                                                                   |
| `--output-file`  | Append results to a file as JSON lines.                                                                                                |
| `--environment`  | The environment ID. Defaults to the active environment.                                                                                |
| `--cluster`      | The Kafka cluster ID, for resource types that need one. Defaults to the<br/>active cluster.                                            |
| `-o`, `--output` | The output format: `human`, `json`, or `yaml`. The default is<br/>`human`.                                                             |

### Set the time window

Each log source limits how far back you can query. The `Lookback` column in
the `confluent logs source list` output shows the limit. A window that reaches
further back returns an error.

To fetch logs from the last hour, use `--since`:

```bash
confluent logs fetch lkc-abc123 --source cluster-health --since 1h
```

To fetch logs from a fixed window, use `--from` and `--to`:

```bash
confluent logs fetch lkc-abc123 --source cluster-health \
  --from 2026-12-01T00:00:00Z --to 2026-12-01T12:00:00Z
```

### Filter logs

Filters combine as follows:

- Different fields must all match.
- A repeated field matches either value.

To fetch only `ERROR` and `WARN` entries for one event type, run:

```bash
confluent logs fetch lkc-abc123 --source cluster-health --since 24h \
  --search level=ERROR,level=WARN --search event_type=SERVICE_MAINTENANCE
```

To search the log messages for a phrase, use `--search-text`. Wildcards such
as `*` and `?` match across the text fields:

```bash
confluent logs fetch lcc-123456 --source connector-logs --since 24h \
  --search level=ERROR --search-text "discon*"
```

### Limit and page results

To return only the most recent entries, use `--tail`:

```bash
confluent logs fetch lkc-abc123 --source cluster-health --since 7d --tail 10
```

To get the next page of a query, run the same command with `--next`. The CLI
stores the last query, so the flags must match. When no pages remain, the CLI
prints `No more pages for this query.`

```bash
confluent logs fetch lkc-abc123 --source cluster-health --since 7d --next
```

### Choose an output format

The default `human` output is a table of the default columns for the log
source. To get every field of each record, use `-o json` or `-o yaml`.

To append the records to a file as JSON lines, use `--output-file`. The CLI
prints nothing when the command succeeds.

```bash
confluent logs fetch lcc-123456 --source connector-logs --since 24h \
  --search level=ERROR --output-file errors.jsonl
```

## Fetch cluster health logs

To fetch the `ERROR` events for a cluster from the last hour, run:

```bash
confluent logs fetch lkc-abc123 --source cluster-health --since 1h \
  --search level=ERROR
```

Your output should resemble:

```text
Found 1 log entry for cluster-health on lkc-abc123:

        Timestamp        | Level |       Event Type        |      Message
-------------------------+-------+-------------------------+------------------
  2026-12-01T09:41:12Z   | ERROR | SERVICE_ISSUE_DETECTED  | Elevated latency
```

## Fetch connector logs

To fetch the `ERROR` logs for a connector from the last 24 hours, run:

```bash
confluent logs fetch lcc-123456 --source connector-logs --since 24h \
  --search level=ERROR --search-text "example error"
```

Your output should resemble:

```text
Found 1 log entry for connector-logs on lcc-123456:

        Timestamp        | Level | Task ID |            Message
-------------------------+-------+---------+----------------------------
  2026-12-01T08:42:10Z   | ERROR | task-0  | Connection was lost.
```

## Troubleshoot errors

The command checks your flags before it sends a request. These errors name the
fix:

- `--source is required`: add `--source` with a name from
  `confluent logs source list`.
- `is not a search field`: run `confluent logs source describe` to see the
  valid search fields and values.
- `does not match log source`: use a resource ID that fits the log source.
- `--since cannot be used with --from or --to`: use one kind of window.
- `rate limit exceeded`: wait for the number of seconds that the error shows,
  and run the command again.

## Related content

- [View Connector Events for Confluent Cloud](../connectors/logging-cloud-connectors.md#ccloud-connector-logging)
