# Show events from any command

Send the output of a command to streamview. If the command prints JSON objects, streamview shows them as events.

Source: https://www.eventcatalog.dev/tools/streamview/docs/how-to/show-events-from-any-command

`streamview serve -` reads the output of a different command.
If the command prints JSON objects, streamview shows each object as an event.
Thus you can show a log file, the logs of a container, a database table, or the answer of an HTTP API.

The objects do not have to be CloudEvents. You tell streamview which fields to use.

Some steps on this page use `jq`, a program that changes JSON.

If this is new to you, do the tutorial [Send JSON records to streamview](https://www.eventcatalog.dev/tools/streamview/docs/tutorials/send-json-records) first.

## Find the three fields

1. Print one record of your data.
2. Find the field that gives the kind of event, for example `event`. This is the value of `--type-field`.
3. Find the field that gives the time, for example `ts`. This is the value of `--time-field`.
4. Find the field that the events of one order share, for example `orderId`. This is the value of `--correlation-field`.

Only the first of the three is important for a live view. Each kind of event gets a lane of its own.

- If the field is in an object, use a period: `payload.orderId`.
- If no field gives the kind of event, use `--type TEXT`. Then all records are in one lane.
- If no field gives the time, streamview uses the time when it read the record.

streamview knows some usual field names. If your records use them, you do not need the options.
See [Events from plain JSON records](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#events-from-plain-json-records).

## Follow a log file

Use this when a program writes one JSON object on each line of a file.

```
tail -n +1 -f app.log | streamview serve - \
  --type-field event --time-field ts --correlation-field orderId --open
```

`tail -n +1 -f` prints the full file, and then each new line.
The page shows each new event approximately 2 seconds after the program writes it.

## Follow the logs of a container

```
docker logs -f my-container 2>&1 | streamview serve - \
  --type-field event --correlation-field orderId --open
```

`docker logs -f` prints the old lines, and then each new line.
`2>&1` also sends the lines that the container writes to standard error.

streamview rejects a line that is not a JSON object. The other lines continue to show.

## Load the rows of a database table

This example reads an outbox table from PostgreSQL. Each row becomes one record.

```
psql "postgres://USER:PASSWORD@HOST:5432/DATABASE" -At \
  -c "select row_to_json(o) from outbox o order by created_at" \
  | streamview serve - --db outbox.db \
  --type-field event_type --time-field created_at --correlation-field payload.orderId --open
```

- `row_to_json` makes one JSON object from each row.
- `-At` prints only the rows, with no table lines.
- `order by created_at` gives the rows in time sequence.

When the command reaches the last row, the terminal shows a line such as this:

```
-: end of input, 300 events accepted, 0 rejected
```

## Load the answer of an HTTP API

Many APIs give a JSON array. `jq` prints each item of the array on a line of its own.
This example shows the public events of GitHub:

```
curl -s https://api.github.com/events | jq -c 'sort_by(.created_at)[]' \
  | streamview serve - --db github.db \
  --type-field type --time-field created_at --correlation-field repo.name --open
```

`sort_by(.created_at)` puts the items in time sequence. This API gives the newest item first.

To get new items continuously, run the request in a loop:

```
while true; do
  curl -s https://api.github.com/events | jq -c 'sort_by(.created_at)[]'
  sleep 60
done | streamview serve - --db github.db \
  --type-field type --time-field created_at --correlation-field repo.name --open
```

The API gives many of the same items each time. streamview keeps one copy of a record that has a time and the same text.

## Take the records out of a larger object

Some files have all records in one JSON object. An AWS CloudTrail file is an example: its records are in the `Records` field.

```
jq -c '.Records[]' trail.json | streamview serve - --db trail.db \
  --type-field eventName --time-field eventTime --sort --open
```

## Change a text log to JSON

If a log is text, `jq` can make a JSON object from each line.
This example reads lines such as `2026-12-01T10:00:00Z INFO order.placed ord_1`:

```
jq -Rc 'capture("^(?<time>\\S+) (?<level>\\S+) (?<event>\\S+) (?<order>\\S+)$")' app.txt \
  | streamview serve - --db app.db --type-field event --correlation-field order --sort --open
```

Each name in `(?<name>…)` becomes a field. `jq` does not print a line that is different from the pattern.

To follow the text log while the program writes it, add `--unbuffered` to `jq`, and do not use `--sort`:

```
tail -n +1 -f app.txt \
  | jq --unbuffered -Rc 'capture("^(?<time>\\S+) (?<level>\\S+) (?<event>\\S+) (?<order>\\S+)$")' \
  | streamview serve - --db app.db --type-field event --correlation-field order --open
```

Without `--unbuffered`, `jq` holds its output, and the page stays empty.

## Give the lanes an icon

Each lane shows a general icon. An icon of your own helps you to find a lane quickly.

For one icon for all lanes, add `--icon`. The value can be an emoji, an image file, or the address of an image:

```
tail -n +1 -f app.log | streamview serve - --type-field event --icon 🪵
```

```
tail -n +1 -f app.log | streamview serve - --type-field event --icon logo.svg
```

For a different icon for each lane, put the icon in the records, and add `--icon-field` with the name of that field.
`jq` can add the field:

```
tail -n +1 -f app.log | jq -c --unbuffered '.icon = (if .service == "db" then "🗄️" else "🪵" end)' | streamview serve - --type-field event --icon-field icon
```

If you send CloudEvents, put the `icon` attribute in the event. You do not need an option.
[The icon of a lane](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#the-icon-of-a-lane) gives the values that an icon can have.

## Select between a live view and an archive

| Your command | Use `--sort` | What you see |
|---|---|---|
| Does not stop, for example `tail -f` | No | Each event, approximately 2 seconds after it arrives. |
| Stops, and its records are in time sequence | No | The events while streamview reads them. |
| Stops, and its records are not in time sequence | Yes | All events, when the command stops. |

For old events, use `--db` with a new file name. Do not load old events into a store that has newer events.
See [Time and sequence of events](https://www.eventcatalog.dev/tools/streamview/docs/explanation/time-and-sequence).

## If the page does not show what you expect

- **The page is empty.** A command in the pipe holds its output. For `jq`, add `--unbuffered`. With `--sort`, the page is empty until the command stops.
- **All events are at one time.** streamview did not find a time. Give the field with `--time-field`.
- **All events are in one lane.** streamview did not find the kind of event. Give the field with `--type-field`.
- **There are hundreds of lanes.** The type field has too many different values, for example a full log message. Use a field that has few values.
- **Events are missing.** Open `http://localhost:4747/api/stats`. The `rejected` number counts the lines that are not JSON objects.

## Related

- [Show events from an S3 bucket](https://www.eventcatalog.dev/tools/streamview/docs/how-to/show-events-from-s3)
- [Show events from a file, a program, or HTTP](https://www.eventcatalog.dev/tools/streamview/docs/how-to/show-your-own-events)
- [Events from plain JSON records](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#events-from-plain-json-records)
- [Command line: streamview serve](https://www.eventcatalog.dev/tools/streamview/docs/reference/command-line#streamview-serve)
