# `Chronicle.EventLog`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/event_log.ex#L4)

Appends and queries events in a Chronicle event log.

The event log is the primary `EventSequence` in Chronicle. Use `append/3` to
record domain events for a given event source (such as an aggregate root).

## Usage

    :ok = Chronicle.EventLog.append("account-1", %MyApp.Events.AccountOpened{
      account_id: "account-1",
      owner_name: "Alice",
      initial_balance: 500
    })

To append to a specific client:

    :ok = Chronicle.EventLog.append("account-1", event, client: :my_chronicle)

## Multiple events

    events = [
      %MyApp.Events.AccountOpened{account_id: "1", owner_name: "Alice"},
      %MyApp.Events.FundsDeposited{account_id: "1", amount: 500}
    ]
    :ok = Chronicle.EventLog.append_many("account-1", events)

# `append`

```elixir
@spec append(String.t(), struct(), keyword()) :: :ok | {:error, term()}
```

Appends a single event to the event log for the given event source.

## Options

  * `:client` — the client name (default: `Chronicle.Client`)
  * `:namespace` — overrides the client's default namespace
  * `:event_source_type` — the event source type (default: `""`)
  * `:event_stream_type` — the event stream type (default: `""`)
  * `:event_stream_id` — the event stream ID (default: `""`)
  * `:tags` — list of tag strings
  * `:subject` — the identity subject string

Returns `:ok` on success or `{:error, reason}` on failure.

# `append_many`

```elixir
@spec append_many(String.t(), [struct()], keyword()) :: :ok | {:error, term()}
```

Appends multiple events to the event log for the given event source.

All events are appended atomically. Each event must be a struct that
`use Chronicle.EventType`.

## Options

Same as `append/3`.

# `get_for_event_source`

```elixir
@spec get_for_event_source(
  String.t(),
  keyword()
) :: {:ok, list()} | {:error, term()}
```

Returns events for the given event source ID from the event log.

## Options

  * `:client` — the client name (default: `Chronicle.Client`)
  * `:namespace` — overrides the client's default namespace
  * `:event_types` — list of event type modules to filter by (default: all)

Returns `{:ok, [appended_event]}` or `{:error, reason}`.

---

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