Caddy.Logger.Handler (Caddy v2.3.1)

View Source

Default telemetry handler that forwards log events to Elixir's Logger.

Automatically attached by Caddy.Logger unless disabled via configuration:

config :caddy, attach_default_handler: false

Respects configured log level:

config :caddy, log_level: :info  # Only :info and above

Telemetry Events Handled

This handler listens to:

  • [:caddy, :log, :debug]
  • [:caddy, :log, :info]
  • [:caddy, :log, :warning]
  • [:caddy, :log, :error]
  • [:caddy, :log, :received] - Caddy process output

Performance

This handler is designed to be lightweight with minimal memory allocation. It forwards events synchronously to Elixir's Logger, which handles buffering and I/O asynchronously.

Summary

Functions

Attaches the default handler to all Caddy log events.

Detaches the default handler.

Functions

attach()

@spec attach() :: :ok | {:error, term()}

Attaches the default handler to all Caddy log events.

Returns :ok if successful, or {:error, :already_exists} if the handler is already attached.

detach()

@spec detach() :: :ok | {:error, :not_found}

Detaches the default handler.