# `Grizzly.Trace`
[🔗](https://github.com/smartrent/grizzly/blob/v9.1.4/lib/grizzly/trace.ex#L1)

Module that tracks the commands that are sent and received by Grizzly

The trace will hold in memory the last 300 messages. If you want to generate
a log file of the trace records you use `Grizzly.Trace.dump/1`.

The log format is:

```
timestamp source destination sequence_number command_name command_parameters
```

If you want to list the records that are currently being held in memory you
can use `Grizzly.Trace.list/0`.

If you want to start traces from a fresh start you can call
`Grizzly.Trace.clear/0`.

# `dest`

```elixir
@type dest() :: Grizzly.node_id() | :grizzly
```

# `format`

```elixir
@type format() :: :text | :raw
```

# `list_opt`

```elixir
@type list_opt() :: {:node_id, Grizzly.node_id()}
```

# `log_opt`

```elixir
@type log_opt() :: {:src, src()} | {:dest, dest()}
```

# `print_opt`

```elixir
@type print_opt() :: list_opt() | {:decode, boolean()}
```

# `src`

```elixir
@type src() :: Grizzly.node_id() | :grizzly
```

# `trace_opt`

```elixir
@type trace_opt() ::
  {:name, atom()} | {:size, pos_integer()} | {:record_keepalives, boolean()}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear`

```elixir
@spec clear(GenServer.server()) :: :ok
```

Reset the trace buffer.

# `dump`

```elixir
@spec dump(binary()) :: :ok | {:error, atom()}
```

Dump trace records into a file using Erlang External Term Format.

# `format`

# `format`

# `format`

```elixir
@spec format([Grizzly.Trace.Record.t()], format(), keyword()) :: binary()
```

Serialize a list of trace records into a binary. The format can be one of:

* `:text` - Each record is on a new line and is
  formatted as `timestamp source destination sequence_number command_name
  command_binary`. This is the default format.

* `:raw` - Each record is on a new line and is formatted as
  `timestamp source -> destination: binary`.

# `list`

```elixir
@spec list() :: [Grizzly.Trace.Record.t()]
```

See `list/2`.

# `list`

```elixir
@spec list(GenServer.server() | [list_opt()]) :: [Grizzly.Trace.Record.t()]
```

See `list/2`.

# `list`

```elixir
@spec list(GenServer.server(), [list_opt()]) :: [Grizzly.Trace.Record.t()]
```

List all records in the trace buffer.

# `log`

```elixir
@spec log(GenServer.server(), src(), dest(), binary()) :: :ok
```

Add a record to the trace buffer.

# `print`

```elixir
@spec print() :: :ok
```

# `print`

# `print`

```elixir
@spec print([Grizzly.Trace.Record.t()] | format(), [print_opt()]) :: :ok
```

Write trace records to standard out. See `format/2` for the available formats.

# `record_keepalives`

```elixir
@spec record_keepalives(boolean()) :: :ok
```

See `record_keepalives/2`.

# `record_keepalives`

```elixir
@spec record_keepalives(GenServer.server(), boolean()) :: :ok
```

Enable or disable logging of keepalive frames.

# `resize`

```elixir
@spec resize(GenServer.server(), pos_integer()) :: :ok
```

Change the max size of the trace buffer from the default of 300.

# `start_link`

```elixir
@spec start_link([trace_opt()]) :: GenServer.on_start()
```

Start the trace server.

---

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