View Source TelemetryLoggers.PlugLogger (TelemetryLogger v0.0.1)

Logs one log per request on a Phoenix router.

It includes the following metadata:

  • duration_us: The duration in microseconds
  • status: The response HTTP status
  • method: The request HTTP method
  • path: The request path (can be hidden by passing include_path: false)

If Phoenix is present and the router is passed

  • route: The matched Phoenix Route
  • route_plug: The plug of the matched route, probably your controller
  • route_plug_opts: The plug options of the matched route, probably your action name

To set this up properly, you want to disable Phoenix built-in logger by adding to your config:

config :phoenix, :logger, false

Then you need to attach this during application boot with

TelemetryLogger.attach_loggers([PlugLogger])

For Phoenix applications, you probably want to specify the PlugLogger

TelemetryLogger.attach_loggers([{PlugLogger, router: MyAppWeb.Router}])

By default it will log on :info level, you can change that by passing level: level when attaching, for example:any()

TelemetryLogger.attach_loggers([{PlugLogger, level: :debug}])

options

Options

This logger accepts the following options

  • :level - The log level to use. By default it uses :info
  • :router - The Phoenix router of your application so this can extract route information. If not provided, route information will never be included.
  • :include_path - Some sensitive applications might want to make sure path params are not leaked in the logs as they might contain sensistive information. For these cases, include_path: false will disable that and will only log route information (e.g. /user/:id instead of /user/12345). This is true by default.
  • :prefix - The prefix of the Plug.Telemetry events, by default it is [:phoenix, :endpoint]