UnifiApi.Network.SystemLog (UnifiApi v0.4.0)

Copy Markdown View Source

UniFi Network API (v2) — system log.

Returns the controller's structured system log: device adoption, firmware updates, gateway events, threat-management actions, etc. This is more focused than UnifiApi.Network.Events — events covers all client/AP activity, system log covers controller-level operations.

Requires cookie + CSRF authentication. See UnifiApi.Auth.Cookie.

Common entry fields

  • id, timestamp, category, level
  • key, subsystem
  • description — human-readable message
  • device — when the log line is device-attributed

Summary

Functions

Returns all system log entries within the supported window.

Returns a lazy stream that auto-paginates the system log via pageSize / pageNumber.

Functions

list_all(client, site_id, opts \\ [])

@spec list_all(Req.Request.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, UnifiApi.Error.t()}

Returns all system log entries within the supported window.

Options

  • :limit — server-side cap (pageSize query param). Default 200 (reduced from 500 in v0.4.0 to bound per-page memory).
  • :start — bucket start (pageNumber query param).
  • :raw — when true, return the raw response body binary (skips JSON decoding) — useful for streaming parsers on very large logs.

stream(client, site_id, opts \\ [])

@spec stream(Req.Request.t(), String.t(), keyword()) :: Enumerable.t()

Returns a lazy stream that auto-paginates the system log via pageSize / pageNumber.

Error contract

A mid-stream error does not raise by default: the stream halts and yields {:error, %UnifiApi.StreamError{}, last_page} as its final element, so the enumerable is heterogeneous. Match the tail:

case Enum.to_list(stream) do
  items when is_list(items) ->
    case List.last(items) do
      {:error, error, cursor} -> {:error, error, cursor}
      _ -> {:ok, items}
    end
end

Pass raise_errors: true to raise UnifiApi.StreamError instead.

Options

  • :limit — page size (default 200, reduced from 500 in v0.4.0 to bound per-page memory), sent as pageSize.
  • :max_pages — halt after this many successful pages (default: unbounded).
  • :max_items — halt once this many entries have been yielded; the final page is truncated to fit (default: unbounded).
  • :raise_errors — when true, raise UnifiApi.StreamError on a mid-stream error instead of yielding {:error, reason, last_page} as the final element (default: false).

:max_pages, :max_items and :raise_errors are forwarded verbatim to UnifiApi.Client.stream_paged/2 and behave exactly as they do in UnifiApi.Client.stream/3. Any other key raises ArgumentError.

Examples

# The 500 most recent entries, without walking the whole log
UnifiApi.Network.SystemLog.stream(authed, "default", max_items: 500)
|> Enum.to_list()