View Source LoggerJSON.Ecto (logger_json v6.2.1)
A telemetry handler that logs Ecto query metrics in JSON format.
This module is not recommended to be used in production, as it can be costly to log every single database query.
Summary
Functions
Attaches the telemetry handler to the given event.
A telemetry handler that logs Ecto query along with it's metrics in a structured format.
Functions
@spec attach( name :: String.t(), event :: [atom()], level :: Logger.level() | {module :: module(), function :: atom(), arguments :: [term()]} | false ) :: :ok | {:error, :already_exists}
Attaches the telemetry handler to the given event.
Available options
:level
- log level which is used to log requests. Defaults to:info
.
Dynamic log level
In some cases you may wish to set the log level dynamically
on a per-query basis. To do so, set the :level
option to
a tuple, {Mod, Fun, Args}
. The query and map of time measures
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.
Examples
Attaching the telemetry handler to the MyApp.Repo
events with the :info
log level:
LoggerJSON.Ecto.attach("logger-json-queries", [:my_app, :repo, :query], :info)
For more details on event and handler naming see
(Ecto.Repo
documentation)[https://hexdocs.pm/ecto/Ecto.Repo.html#module-telemetry-events].
@spec telemetry_logging_handler( event_name :: [atom()], measurements :: %{ query_time: non_neg_integer(), queue_time: non_neg_integer(), decode_time: non_neg_integer(), total_time: non_neg_integer() }, metadata :: %{query: String.t(), repo: module()}, level :: Logger.level() | {module :: module(), function :: atom(), arguments :: [term()]} | false ) :: :ok
A telemetry handler that logs Ecto query along with it's metrics in a structured format.