View Source Ecto.DevLogger (ecto_dev_logger v0.14.1)

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 representation (binary UUID, DateTime, Decimal, json, etc). Also, it highlights db time to make slow queries noticeable. 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

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

Functions

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

Gets the handler_id for a given Repo.

Link to this function

install(repo_module, opts \\ [])

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

Attaches telemetry_handler/4 to 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 will add the repo name into the log.
  • :ignore_event - a callback which allows to skip some telemetry events thus skip printing logs. By default, the library ignores events from Oban and events related to migration queries. These checks are not overridable by :ignore_event callback and have priority over it.
  • :before_inline_callback - a callback which allows to modify the query before inlining of bindings. You can use this option to format the query using external utility, like pgformatter, etc.
Link to this function

telemetry_handler(event_name, measurements, metadata, config)

View Source

Telemetry handler which logs queries.

@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