PhoenixKitOG.ActivityLog (PhoenixKitOG v0.3.7)

Copy Markdown View Source

Thin wrapper around PhoenixKit.Activity.log/3 for the OG plugin.

Every entry is stamped with module: "phoenix_kit_og" so the admin activity feed can filter to just this plugin's events. Callers pass the pipe-friendly {:ok, struct} shape so the return value chains cleanly through context functions. Core never raises — a missing activities table on a fresh host, or any other failure, is logged there and returned — so logging never breaks the mutation.

Metadata is PII-safe by convention: names, statuses, counts, UUIDs are OK; email / phone / free-text / anything a user could paste in is not.

Summary

Functions

Pipe step for context functions returning {:ok, struct}. Logs the action and returns the value unchanged. {:error, _} short-circuits to a no-op so callers can put this at the tail of the pipe.

Log without the pipe wrapper — for transactions, toggles, and other paths where the caller doesn't have a {:ok, struct} in hand.

Functions

log(ok, action, opts, fields_fn)

@spec log({:ok, struct()} | {:error, term()}, String.t(), keyword(), (struct() ->
                                                                  map())) ::
  {:ok, struct()} | {:error, term()}

Pipe step for context functions returning {:ok, struct}. Logs the action and returns the value unchanged. {:error, _} short-circuits to a no-op so callers can put this at the tail of the pipe.

Example

%Template{}
|> Template.changeset(attrs)
|> Repo.insert()
|> ActivityLog.log("template.created", opts, &template_activity_fields/1)

maybe_log(action, opts, fields)

@spec maybe_log(String.t(), keyword(), map()) :: :ok

Log without the pipe wrapper — for transactions, toggles, and other paths where the caller doesn't have a {:ok, struct} in hand.