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

The Logging Extension.

Send logs to NervesHub for easy debugging.

This extension is in early release and is off by default. To turn it on, name
it in `extension_modules`, along with the other extensions you want — the list
replaces the defaults rather than adding to them:

    config :nerves_hub_link,
      extension_modules: [
        NervesHubLink.Extensions.Geo,
        NervesHubLink.Extensions.Health,
        NervesHubLink.Extensions.LocalShell,
        NervesHubLink.Extensions.NetworkIdentity,
        NervesHubLink.Extensions.Logging
      ]

Like every extension, it sends nothing until NervesHub asks the device to
attach it.

Naming this also registers `NervesHubLink.Extensions.Logging.Batched`, which
is version 0.1.0 of the same extension: it collects lines and sends a minute
of them per message rather than a message per line. The device offers
whichever version the platform has, so there is nothing to add for it.

Every log line is a message over the socket, so only `:info` and above are sent
by default. Devices on metered connections will want to raise that:

    config :nerves_hub_link,
      logging: [level: :warning]

Any [Logger level](`t:Logger.level/0`) is accepted, as is `:all` to send
everything the `Logger` level allows through.

Each line also carries the metadata `Logger` attached to it, which is
everything by default. That includes the pid and group leader of the process
that logged, and on a crash the whole reason and stacktrace. Name the keys to
send less:

    config :nerves_hub_link,
      logging: [metadata: [:mfa, :file, :line]]

The timestamp is always sent, whatever that is set to. NervesHub reads it to
know when the line was written, and drops a line it cannot read one from.

# `send_log_line`

```elixir
@spec send_log_line(atom(), IO.chardata(), map()) :: :ok
```

Request a log payload be sent asynchronously.

## Examples

    iex> NervesHubLink.Extensions.Logging.send_log_line(:info, "hello, it's me", %{sensor: "door lock"})
    :ok

---

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