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 microsecondsstatus
: The response HTTP statusmethod
: The request HTTP methodpath
: The request path (can be hidden by passinginclude_path: false
)
If Phoenix is present and the router is passed
route
: The matched Phoenix Routeroute_plug
: The plug of the matched route, probably your controllerroute_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 thePlug.Telemetry
events, by default it is[:phoenix, :endpoint]