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

# Logging extension

> Send a Nerves device's log lines to NervesHub with the Logging extension, then read them in the web UI, the CLI or the API.

The Logging extension sends the device's `Logger` output to NervesHub, where it is stored against the device and can be searched.

## Requirements

* `nerves_hub_link` 2.13.0 or later. The extension is in early release and is not in the default extension list.
* NervesHub 2.3.0 or later for one line per message. NervesHub 2.5.0 or later for batched sending.
* ClickHouse on the instance. Without it, NervesHub does not offer the extension to devices and nothing is stored. See [Feature prerequisites](https://docs.nerves-hub.org/hosting/feature-prerequisites.md#clickhouse).

## Enable it

**1. Add Logging to your firmware**

Name the module in `extension_modules`:

```elixir theme={null}
config :nerves_hub_link,
  extension_modules: [
    NervesHubLink.Extensions.Geo,
    NervesHubLink.Extensions.Health,
    NervesHubLink.Extensions.NetworkIdentity,
    NervesHubLink.Extensions.Logging
  ]
```

> [!WARNING]
>
> `extension_modules` replaces the default list. Name every extension you want. The list leaves out the optional [Local shell](https://docs.nerves-hub.org/extensions/local-shell.md) extension.

**2. Turn it on for the product**

In **Product settings**, on the **General** tab, switch on **Logging** in the **Device extensions** card. A product created in the web UI starts with every extension on. A product created through the API or `nh` starts with every extension off.

**3. Check the device setting**

On the device's **Settings** tab, **Logging** in the **Extensions** card is on by default.

## Check that it works

Reconnect the device if it was connected before you turned Logging on. Open the device and select the **Logs** tab. Lines appear as the device sends them. With batched sending, expect the first lines up to a minute after the extension attaches.

The tab tells you when something is off:

| Message | What to do |
| - | - |
| Analytics aren't enabled for your platform. | The instance has no ClickHouse. |
| Device logs aren't enabled for this product. | Turn on **Logging** in the product settings. |
| Device logs aren't enabled. | Turn on **Logging** on the device's **Settings** tab. |
| No logs have been received yet. | The extension is on but nothing has arrived. Check the firmware config. |

## Choose what is sent

Only `:info` and above are sent by default. Raise the level on metered connections:

```elixir theme={null}
config :nerves_hub_link,
  logging: [level: :warning]
```

Any `Logger` level is accepted, and `:all` sends everything the `Logger` level lets through.

Each line carries the metadata `Logger` attached to it. That is everything by default, including the pid of the process that logged and, on a crash, the reason and stacktrace. To send less, name the keys you want:

```elixir theme={null}
config :nerves_hub_link,
  logging: [metadata: [:mfa, :file, :line]]
```

The timestamp is always sent.

## Batched sending

The extension has two versions. Naming `NervesHubLink.Extensions.Logging` registers both, and the device offers whichever your NervesHub has, preferring 0.1.0.

| | 0.0.1 | 0.1.0 (batched) |
| - | - | - |
| Needs NervesHub | 2.3.0 | 2.5.0 |
| Sends | One message per line | A minute of lines per message |
| Collects from | The moment the extension attaches | Application start, so boot logs are included |
| OTP reports (crashes, supervisor reports) | Skipped | Sent, on one line and bounded in length |

NervesHub limits how often a device may send, not how much each message carries. At one message per line, a device that logs fast loses lines to the limit. NervesHub drops messages over the limit without telling the device.

The batched version holds lines in a bounded buffer and reports what it had to drop:

```elixir theme={null}
config :nerves_hub_link,
  logging: [
    level: :info,
    # How many lines the collector holds before dropping the oldest.
    max_lines: 1000,
    # Never less than 60, whatever you put here.
    interval_seconds: 60
  ]
```

## Limits

* A single line longer than 8KB is cut short and marked.
* NervesHub accepts at most 100 lines in one batched message. It drops the rest and stores a line saying how many were dropped.
* Log lines are kept for 3 days. The period is fixed. See [ClickHouse retention](https://docs.nerves-hub.org/hosting/clickhouse.md#retention).

## Read logs in the web UI

The device's **Logs** tab shows the newest lines and adds new ones as they arrive. On NervesHub 2.5.1 and later you can use **Search messages**, filter by **Level** and **Time**, and scroll back up to 1000 lines.

## Read logs with the CLI

`nh device logs` prints the lines a device has sent. It needs an organization and product, from `--org` and `--product` or your [CLI configuration](https://docs.nerves-hub.org/cli/configuration.md).

```bash theme={null}
nh device logs thermostat-4021
```

Lines are newest first by default. Narrow them with flags:

```bash theme={null}
nh device logs thermostat-4021 --level error,warning --limit 50
nh device logs thermostat-4021 --search "sensor bus"
nh device logs thermostat-4021 --since 2h --order asc
```

Follow new lines until you press `Ctrl+C`:

```bash theme={null}
nh device logs thermostat-4021 --follow
```

**--level** `strings`

Only lines at these levels. Repeat the flag or separate levels with commas. Levels are matched exactly: `--level warning` does not include `error`.

**--search** `string`

Only lines whose message contains this text. The match ignores case and is literal, so `%` and `_` are not wildcards.

**--since** `string`

Only lines at or after this time. Accepts an ISO 8601 timestamp (`2026-08-16T09:14:00Z`) or an offset from now (`30m`, `2h`, `3d`).

**--before** `string`

Only lines before this time. Accepts the same formats as `--since`. It is exclusive, so you can pass the oldest timestamp of one page as the next `--before`. Cannot be used with `--follow`.

**--limit** `integer` (default: 100)

Maximum lines to return, from 1 to 1000.

**--order** `string` (default: desc)

`desc` for newest first, or `asc` for oldest first. Cannot be used with `--follow`, which always prints oldest first.

**--meta** `boolean`

Append the metadata the device attached to each line, as `key=value` pairs.

**-f, --follow** `boolean`

Print the most recent lines, then keep printing new ones until interrupted. This polls the API. There is no streaming endpoint.

**--interval** `duration` (default: 2s)

How often `--follow` polls.

Add the global `-o json` flag for JSON output. A one-shot command prints a single array. With `--follow`, it prints one JSON object per line:

```bash theme={null}
nh device logs thermostat-4021 --level error --since 24h -o json
```

## Read logs with the API

```text theme={null}
GET /api/orgs/{org_name}/products/{product_name}/devices/{identifier}/logs
GET /api/devices/{identifier}/logs
```

The query parameters match the CLI flags: `level`, `search`, `since`, `before`, `limit` and `order`. An instance without ClickHouse answers `501`. See the [API overview](https://docs.nerves-hub.org/api/overview.md).

Turning the extension off stops new lines arriving. Lines already stored stay readable until they expire.

## Related pages

* [Extensions overview](https://docs.nerves-hub.org/extensions/overview.md)
* [Error reports extension](https://docs.nerves-hub.org/extensions/error-reports.md)
* [`nh device logs`](https://docs.nerves-hub.org/cli/reference#nh-device-logs)
* [HTTP API overview](https://docs.nerves-hub.org/api/overview.md)
* [ClickHouse for a self-hosted instance](https://docs.nerves-hub.org/hosting/clickhouse.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.