# `NervesHubLink.Extensions.Logging.Collector`
[🔗](https://github.com/nerves-hub/nerves_hub_link/blob/v2.14.0/lib/nerves_hub_link/extensions/logging/collector.ex#L5)

Holds the device's log lines until the Logging extension sends them.

Runs from application start, not from the extension being attached. Lines
written while a device is booting, or while it is offline, or while NervesHub
is still deciding whether it wants logging at all, are the ones an operator
goes looking for, and none of them exist by the time the extension starts.

## The bound

A device can write faster than a minute's worth of lines can be sent, and a
device the platform never attaches keeps writing regardless. So this holds a
fixed number of lines and drops the oldest past it, counting what went. The
count goes out as a line of its own ahead of the survivors, because a gap
someone can see beats a gap they cannot.

## Where the lines come from

A `:logger` handler, which runs in the process doing the logging. Everything
it does is a `send/2` to this process, since anything slower would charge the
application for the reporting, and anything that logs would recurse.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `count`

```elixir
@spec count() :: non_neg_integer()
```

How many lines are waiting, the drop notice included.

# `sent`

```elixir
@spec sent(non_neg_integer()) :: :ok
```

Forget the first `count` lines `take/1` returned, now that they have gone.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start collecting.

## Options

  * `:max_lines` - how many lines to hold. Defaults to what
    `NervesHubLink.Extensions.Logging.Config.max_lines/0` reports.
  * `:level` - the lowest level to collect, as `Logger` names it. Defaults to
    `:info`. Filtering happens in `:logger`, so a line below this costs the
    application nothing.

# `take`

```elixir
@spec take(pos_integer()) :: [map()]
```

The next lines to send, oldest first, at most `max` of them.

Left where they are. Paired with `sent/1` rather than handing them over,
because a push can fail and lines taken out of here and then not sent are
exactly what this exists to prevent.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
