ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - fuelen/ecto_dev_logger: An alternative logger for Ecto queries
An alternative logger for Ecto queries. Contribute to fuelen/ecto_dev_logger development by creating an account on GitHub.
Visit Site

GitHub - fuelen/ecto_dev_logger: An alternative logger for Ecto queries

GitHub - fuelen/ecto_dev_logger: An alternative logger for Ecto queries

Ecto.DevLogger

Hex.pm

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.

before and after

Installation

The package can be installed by adding ecto_dev_logger to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_dev_logger, "~> 0.14"}
  ]
end

Then disable default logger for your repo in config file for dev mode:

if config_env() == :dev do
  config :my_app, MyApp.Repo, log: false
end

And install telemetry handler in MyApp.Application:

Ecto.DevLogger.install(MyApp.Repo)

Telemetry handler will be installed only if log configuration value is set to false.

That's it.

The docs can be found at https://hexdocs.pm/ecto_dev_logger.

Development Only Installation

If you turn off repo logging for any reason in production, you can configure ecto_dev_logger to only be available in development. In your mix.exs, restrict the installation to :dev:

def deps do
  [
    {:ecto_dev_logger, "~> 0.10", only: :dev}
  ]
end

In MyApp.Application, an additional function is required:

defmodule MyApp.Application do
  @moduledoc "..."

  def start(_type, _args) do
    maybe_install_ecto_dev_logger()

    # ...
  end

  if Code.ensure_loaded?(Ecto.DevLogger) do
    defp maybe_install_ecto_dev_logger, do: Ecto.DevLogger.install(MyApp.Repo)
  else
    defp maybe_install_ecto_dev_logger, do: :ok
  end

  # ...
end

Format queries

It is possible to format queries using a :before_inline_callback option. Here is an example of setup using pgFormatter as an external utility:

defmodule MyApp.Application do
  def start(_type, _args) do
    Ecto.DevLogger.install(MyApp.Repo, before_inline_callback: &__MODULE__.format_sql_query/1)
  end

  def format_sql_query(query) do
    case System.shell("echo $SQL_QUERY | pg_format -", env: [{"SQL_QUERY", query}], stderr_to_stdout: true) do
      {formatted_query, 0} -> String.trim_trailing(formatted_query)
      _ -> query
    end
  end
end

Running tests

You need to run a local postgres server for the tests to interact with. This is one way to do it:

~$ docker run -p5432:5432 --rm --name ecto_dev_logger_postgres -e POSTGRES_PASSWORD=postgres -d postgres

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory