Ecto.DevLogger (ecto_dev_logger v0.15.0)

View Source

An alternative logger for Ecto queries.

It inlines bindings into the query, so it is easy to copy-paste logged SQL and run it in any IDE for debugging without manual transformation of common Elixir terms to string representations (binary UUID, DateTime, Decimal, JSON, etc.). It also highlights DB time to make slow queries noticeable. The source table and inlined bindings are highlighted as well.

Summary

Functions

Gets the handler_id for a given Repo.

Detaches a previously attached handler for a given Repo.

Types

option()

@type option() ::
  {:log_repo_name, boolean()}
  | {:ignore_event, (metadata :: map() -> boolean())}

Functions

handler_id(repo_module)

@spec handler_id(repo_module :: module()) :: list()

Gets the handler_id for a given Repo.

install(repo_module, opts \\ [])

@spec install(repo_module :: module(), opts :: [option()]) ::
  :ok | {:error, :already_exists}

Attaches telemetry_handler/4 to the application.

Returns the result from the call to :telemetry.attach/4 or :ok if the repo has default logging enabled.

Options

  • :log_repo_name - when truthy, adds the repo name to the log output.
  • :ignore_event - a callback that allows skipping specific telemetry events, thus suppressing logs. By default, the library ignores events from Oban and events related to migration queries. These checks are not overridable by the :ignore_event callback and have priority over it.
  • :before_inline_callback - a callback that allows modifying the query before inlining bindings. You can use this option to format the query using an external utility, like pgformatter, etc.

To ignore logging for a single Repo operation, pass log: false via telemetry_options to that call; for example:

Repo.query!("SELECT 1", [], telemetry_options: [log: false])
Repo.insert!(changeset, telemetry_options: [log: false])

telemetry_handler(event_name, measurements, metadata, config)

Telemetry handler which logs queries.

uninstall(repo_module)

@spec uninstall(repo_module :: module()) :: :ok | {:error, :not_found}

Detaches a previously attached handler for a given Repo.

Returns the result from the call to :telemetry.detach/1