Combo.Logger (combo v0.8.0)

View Source

Logging various instrumentation events.

Events

Combo uses the :telemetry library for instrumentation. The following events are published by Combo with the following measurements and metadata:

  • [:combo, :endpoint, :init] - dispatched by Combo.Endpoint after your Endpoint supervision tree successfully starts:

    • Measurement: %{system_time: system_time}
    • Metadata: %{pid: pid(), config: keyword(), module: module(), otp_app: atom()}
    • Disable logging: This event is not logged
  • [:combo, :endpoint, :start] - dispatched by Plug.Telemetry in your endpoint:

    • Measurement: %{system_time: system_time}
    • Metadata: %{conn: Plug.Conn.t, options: Keyword.t}
    • Options: %{log: Logger.level | false}

    • Disable logging: In your endpoint plug Plug.Telemetry, ..., log: Logger.level | false

    • Configure log level dynamically: plug Plug.Telemetry, ..., log: {Mod, Fun, Args}
  • [:combo, :endpoint, :stop] - dispatched by Plug.Telemetry in your endpoint whenever the response is sent:

    • Measurement: %{duration: native_time}
    • Metadata: %{conn: Plug.Conn.t, options: Keyword.t}
    • Options: %{log: Logger.level | false}

    • Disable logging: In your endpoint plug Plug.Telemetry, ..., log: Logger.level | false

    • Configure log level dynamically: plug Plug.Telemetry, ..., log: {Mod, Fun, Args}
  • [:combo, :router_dispatch, :start] - dispatched by Combo.Router before dispatching to a matched route:

    • Measurement: %{system_time: System.system_time}
    • Metadata: %{conn: Plug.Conn.t, route: binary, plug: module, plug_opts: term, path_params: map, pipe_through: [atom], log: Logger.level | false}

    • Disable logging: Pass log: false to the router macro, for example: get("/page", PageController, :index, log: false)
    • Configure log level dynamically: get("/page", PageController, :index, log: {Mod, Fun, Args})
  • [:combo, :router_dispatch, :exception] - dispatched by Combo.Router after exceptions on dispatching a route:

    • Measurement: %{duration: native_time}
    • Metadata: %{conn: Plug.Conn.t, kind: :throw | :error | :exit, reason: term(), stacktrace: Exception.stacktrace()}

    • Disable logging: This event is not logged
  • [:combo, :router_dispatch, :stop] - dispatched by Combo.Router after successfully dispatching a matched route:

    • Measurement: %{duration: native_time}
    • Metadata: %{conn: Plug.Conn.t, route: binary, plug: module, plug_opts: term, path_params: map, pipe_through: [atom], log: Logger.level | false}

    • Disable logging: This event is not logged
  • [:combo, :error_rendered] - dispatched at the end of an error view being rendered:

    • Measurement: %{duration: native_time}
    • Metadata: %{conn: Plug.Conn.t, status: Plug.Conn.status, kind: Exception.kind, reason: term, stacktrace: Exception.stacktrace}
    • Disable logging: Set render_errors: [log: false] on your endpoint configuration
  • [:combo, :socket_connected] - dispatched by Combo.Socket, at the end of a socket connection:

    • Measurement: %{duration: native_time}
    • Metadata: %{endpoint: atom, transport: atom, params: term, connect_info: map, vsn: binary, user_socket: atom, result: :ok | :error, serializer: atom, log: Logger.level | false}

    • Disable logging: use Combo.Socket, log: false or socket "/foo", MySocket, websocket: [log: false] in your endpoint
  • [:combo, :socket_drain] - dispatched by Combo.Socket when using the :drainer option:

    • Measurement: %{count: integer, total: integer, index: integer, rounds: integer}
    • Metadata: %{endpoint: atom, socket: atom, intervasl: integer, log: Logger.level | false}

    • Disable logging: use Combo.Socket, log: false in your endpoint or pass :log option in the :drainer option
  • [:combo, :channel_joined] - dispatched at the end of a channel join:

    • Measurement: %{duration: native_time}
    • Metadata: %{result: :ok | :error, params: term, socket: Combo.Socket.t}

    • Disable logging: This event cannot be disabled
  • [:combo, :channel_handled_in] - dispatched at the end of a channel handle in:

    • Measurement: %{duration: native_time}
    • Metadata: %{event: binary, params: term, socket: Combo.Socket.t}
    • Disable logging: This event cannot be disabled

Parameter filtering

Parameter filtering is provided by the Combo.FilteredParams module. Check it out for more details.

Dynamic log level

In some cases you may wish to set the log level dynamically on a per-request basis. To do so, set the :log option to a tuple, {Mod, Fun, Args}. The Plug.Conn.t() for the request will be prepended to the provided list of arguments.

When invoked, your function must return a Logger.level() or false to disable logging for the request.

For example, in your Endpoint you might do something like this:

  # lib/demo/web/endpoint.ex
  plug Plug.Telemetry,
    event_prefix: [:combo, :endpoint],
    log: {__MODULE__, :log_level, []}

  # Disables logging for routes like /status/*
  def log_level(%{path_info: ["status" | _]}), do: false
  def log_level(_), do: :info

Disabling

When you are using custom logging system it is not always desirable to enable Combo.Logger by default. You can disable default logging by:

config :combo, :logger, false