# `GenMCP.TelemetryLogger`
[🔗](https://github.com/lud/gen_mcp/blob/main/lib/gen_mcp/telemetry_logger.ex#L1)

A `:telemetry` handler that logs the events emitted by the `:gen_mcp`
application.

Attaching it gives you ready-made `Logger` output for the lifecycle and
transport events the library emits, each at a fixed log level. It is the
quickest way to see what the server is doing without writing your own
`:telemetry` handler.

### Attaching the logger

Attach the handler once when your application boots, from your
`Application.start/2` callback:

    defmodule MyApp.Application do
      use Application

      @impl true
      def start(_type, _args) do
        :ok = GenMCP.TelemetryLogger.attach()

        children = [
          # your supervision tree
        ]

        Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
      end
    end

`GenMCP.attach_default_logger/1` is a thin wrapper over `attach/1`, so calling
either one has the same effect. Pass filters to narrow what is logged, for
example to keep only the more severe events:

    :ok = GenMCP.TelemetryLogger.attach(min_log_level: :error)

See `attach/1` for the full list of filters.

### Events

Here are the emitted events for the library, and the corresponding log level
used for each one.

* `[:gen_mcp, :server, :init]` with a log level of `:debug`
* `[:gen_mcp, :server, :start_error]` with a log level of `:error`
* `[:gen_mcp, :transport, :request_rejected]` with a log level of `:debug`
* `[:gen_mcp, :transport, :server_crashed]` with a log level of `:error`
* `[:gen_mcp, :transport, :version_rejected]` with a log level of `:debug`

# `attach`

Attaches the telemetry handler that logs `:gen_mcp` events.

Call this once at startup (see the module doc for placement in
`Application.start/2`). It subscribes a single `:telemetry` handler, named
after this module, to the events listed in the module doc, and returns `:ok`
on success.

By default every event is logged at its mapped level. Pass `filters` to
subscribe to a subset:

  * `:min_log_level` - keep only events whose mapped level is at least this
    severe. For example `min_log_level: :error` drops the `:debug` events and
    keeps the `:error` ones.
  * `:prefixes` - a list of event-name prefixes; keep only events whose name
    starts with one of them. For example `prefixes: [[:gen_mcp, :transport]]`
    keeps only the transport events.

### Examples

Attach every event at its default level:

    :ok = GenMCP.TelemetryLogger.attach()

Attach only transport events logged at `:error` or above:

    :ok =
      GenMCP.TelemetryLogger.attach(
        min_log_level: :error,
        prefixes: [[:gen_mcp, :transport]]
      )

---

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