Phoenix v1.5.3 Phoenix.Logger View Source
Instrumenter to handle logging of various instrumentation events.
Instrumentation
Phoenix uses the :telemetry
library for instrumentation. The following events
are published by Phoenix with the following measurements and metadata:
[:plug_adapter, :call, :start]
- dispatched by Phoenix integration with Cowboy, this includes all requests, such as assets and web socket connections- Measurement:
%{system_time: system_time}
- Metadata:
%{conn: Plug.Conn.t, plug: endpoint}
- Disable logging: not logged by default
- Measurement:
[:plug_adapter, :call, :stop]
- dispatched by Phoenix integration with Cowboy, whenever your endpoint finishes processing successfully- Measurement:
%{duration: native_time}
- Metadata:
%{conn: Plug.Conn.t, plug: endpoint}
- Disable logging: not logged by default
- Measurement:
[:plug_adapter, :call, :exception]
- dispatched by Phoenix integration with Cowboy, whenever there are errors- Measurement:
%{duration: native_time}
- Metadata:
%{conn: Plug.Conn.t, plug: endpoint, kind: kind, reason: reason, stacktrace: stacktrace}
- Disable logging: not logged by default
- Measurement:
[:phoenix, :endpoint, :start]
- dispatched byPlug.Telemetry
in your endpoint, usually after code reloading- 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
- Measurement:
[:phoenix, :endpoint, :stop]
- dispatched byPlug.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
- Measurement:
[:phoenix, :router_dispatch, :start]
- dispatched byPhoenix.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)
- Measurement:
[:phoenix, :router_dispatch, :exception]
- dispatched byPhoenix.Router
after exceptions on dispatching a route- Measurement:
%{duration: native_time}
- Metadata:
%{kind: :throw | :error | :exit, reason: term(), stacktrace: Exception.stacktrace()}
- Disable logging: This event is not logged
- Measurement:
[:phoenix, :router_dispatch, :stop]
- dispatched byPhoenix.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
- Measurement:
[:phoenix, :error_rendered]
- dispatched at the end of an error view being rendered- Measurement:
%{duration: native_time}
- Metadata:
%{status: Plug.Conn.status, kind: Exception.kind, reason: term, stacktrace: Exception.stacktrace}
- Disable logging: Set
render_errors: [log: false]
on your endpoint configuration
- Measurement:
[:phoenix, :socket_connected]
- dispatched byPhoenix.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 Phoenix.Socket, log: false
orsocket "/foo", MySocket, websocket: [log: false]
in your endpoint
- Measurement:
[:phoenix, :channel_joined]
- dispatched at the end of a channel join- Measurement:
%{duration: native_time}
- Metadata:
%{result: :ok | :error, params: term, socket: Phoenix.Socket.t}
- Disable logging: This event cannot be disabled
- Measurement:
[:phoenix, :channel_handled_in]
- dispatched at the end of a channel handle in- Measurement:
%{duration: native_time}
- Metadata:
%{event: binary, params: term, socket: Phoenix.Socket.t}
- Disable logging: This event cannot be disabled
- Measurement:
To see an example of how Phoenix LiveDashboard uses these events to create metrics, visit https://hexdocs.pm/phoenix_live_dashboard/metrics.html.
Parameter filtering
When logging parameters, Phoenix can filter out sensitive parameters
such as passwords and tokens. Parameters to be filtered can be
added via the :filter_parameters
option:
config :phoenix, :filter_parameters, ["password", "secret"]
With the configuration above, Phoenix will filter any parameter
that contains the terms password
or secret
. The match is
case sensitive.
Phoenix's default is ["password"]
.
Phoenix can filter all parameters by default and selectively keep parameters. This can be configured like so:
config :phoenix, :filter_parameters, {:keep, ["id", "order"]}
With the configuration above, Phoenix will filter all parameters,
except those that match exactly id
or order
. If a kept parameter
matches, all parameters nested under that one will also be kept.
Disabling
When you are using custom logging system it is not always desirable to enable
Phoenix.Logger
by default. You can always disable this in general by:
config :phoenix, :logger, false