# `ADK.Plugin.Logging`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/plugin/logging.ex#L1)

A plugin that wraps every run with structured log output.

## Configuration

    # Default — logs at :info level, no model/tool/event logging
    ADK.Plugin.register({ADK.Plugin.Logging, []})

    # Debug level with event contents and model/tool logging
    ADK.Plugin.register({ADK.Plugin.Logging,
      level: :debug,
      include_events: true,
      log_model_calls: true,
      log_tool_calls: true
    })

## Options

- `:level` — Logger level (`:info` | `:debug` | `:warning`). Default `:info`.
- `:include_events` — whether to log each event in `on_event`. Default `false`.
- `:log_model_calls` — whether to log `before_model`/`after_model`. Default `false`.
- `:log_tool_calls` — whether to log `before_tool`/`after_tool`. Default `false`.

## Behaviour

- `before_run/2` — logs run start with agent name and invocation ID; records start time.
- `after_run/3` — logs run end with event count, error count, and elapsed milliseconds.
- `before_model/2` — logs model call start (when `log_model_calls: true`).
- `after_model/2` — logs model call result (when `log_model_calls: true`).
- `before_tool/3` — logs tool call start (when `log_tool_calls: true`).
- `after_tool/3` — logs tool call result (when `log_tool_calls: true`).
- `on_event/2` — logs each event (when `include_events: true`).

## Implementation note

The per-model/tool/event hooks are stateless (no plugin state parameter). To bridge
the run-level configuration into these hooks, `before_run/2` stores the relevant
settings in the process dictionary under `{ADK.Plugin.Logging, :config}`. This is
safe because all hooks within a single `Runner.run/5` call execute in the same
process.

# `config`

```elixir
@type config() :: [
  level: :info | :debug | :warning,
  include_events: boolean(),
  log_model_calls: boolean(),
  log_tool_calls: boolean()
]
```

# `state`

```elixir
@type state() :: %{
  level: :info | :debug | :warning,
  include_events: boolean(),
  log_model_calls: boolean(),
  log_tool_calls: boolean(),
  start_times: %{required(String.t()) =&gt; integer()}
}
```

---

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