View Source LoggerExporter.Loggers.Plug (LoggerExporter v0.4.2)
A plug for logging request information in the format:
method=POST path=/users params=%{"user" => %{"name" => "Juan"}} status=201 duration=101ms
To use it, just plug it into the desired module.
plug LoggerExporter.Loggers.Plug,
log: :debug,
filter_parameters_fn: &Phoenix.Logger.filter_values/1
options
Options
:log
- The log level at which this plug should log its request information. Default is:info
.- Configure log level. The list of supported levels
is available in the
Logger
documentation. - Configure log level dynamically:
plug LoggerExporter.Logger.Plug, log: {Mod, Fun, Args}
- Configure log level. The list of supported levels
is available in the
:filter_parameters_fn
- The Function to call with conn.params. Filter params that doesn't need to be logged i.e. {"password": "[FILTERED]"}.
dynamic-log-level
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/my_app_web/endpoint.ex
plug LoggerExporter.Loggers.Plug,
log: {__MODULE__, :log_level, []}
# Disables logging for routes like /health_check
def log_level(%{path_info: ["health_check"]}), do: false
def log_level(_), do: :info