LoggerJSON.Ecto (logger_json v7.0.3)
View SourceA telemetry handler that logs Ecto query metrics in JSON format.
Please keep in mind that logging all database operations will have a performance impact on your application, it's not recommended to use this module in high-throughput production environments.
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.