{"id":13809105,"url":"https://github.com/fuelen/ecto_dev_logger","last_synced_at":"2025-05-15T12:02:09.259Z","repository":{"id":39340828,"uuid":"478696152","full_name":"fuelen/ecto_dev_logger","owner":"fuelen","description":"An alternative logger for Ecto queries","archived":false,"fork":false,"pushed_at":"2024-11-13T13:30:35.000Z","size":636,"stargazers_count":153,"open_issues_count":1,"forks_count":18,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T19:59:20.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fuelen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-06T19:17:24.000Z","updated_at":"2025-02-17T11:42:37.000Z","dependencies_parsed_at":"2023-12-12T09:24:03.758Z","dependency_job_id":"11637113-a49b-48c8-be4a-e0645ab3941c","html_url":"https://github.com/fuelen/ecto_dev_logger","commit_stats":{"total_commits":38,"total_committers":8,"mean_commits":4.75,"dds":0.1842105263157895,"last_synced_commit":"2f11ca81a4325bc603ba813057f77ec49459e87d"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuelen%2Fecto_dev_logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuelen%2Fecto_dev_logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuelen%2Fecto_dev_logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuelen%2Fecto_dev_logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fuelen","download_url":"https://codeload.github.com/fuelen/ecto_dev_logger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:02:01.956Z","updated_at":"2025-05-15T12:02:09.196Z","avatar_url":"https://github.com/fuelen.png","language":"Elixir","funding_links":[],"categories":["Logging"],"sub_categories":[],"readme":"# Ecto.DevLogger\n\n[![Hex.pm](https://img.shields.io/hexpm/v/ecto_dev_logger.svg)](https://hex.pm/packages/ecto_dev_logger)\n\nAn alternative logger for Ecto queries.\n\nIt inlines bindings into the query, so it is easy to copy-paste logged SQL and run it in any IDE for debugging without\nmanual transformation of common elixir terms to string representation (binary UUID, DateTime, Decimal, json, etc).\nAlso, it highlights db time to make slow queries noticeable. Source table and inlined bindings are highlighted as well.\n\n![before and after](./assets/screenshot.png)\n\n\n## Installation\n\nThe package can be installed by adding `ecto_dev_logger` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:ecto_dev_logger, \"~\u003e 0.14\"}\n  ]\nend\n```\n\nThen disable default logger for your repo in config file for dev mode:\n```elixir\nif config_env() == :dev do\n  config :my_app, MyApp.Repo, log: false\nend\n```\nAnd install telemetry handler in `MyApp.Application`:\n```elixir\nEcto.DevLogger.install(MyApp.Repo)\n```\nTelemetry handler will be installed *only* if `log` configuration value is set to `false`.\n\nThat's it.\n\nThe docs can be found at [https://hexdocs.pm/ecto_dev_logger](https://hexdocs.pm/ecto_dev_logger).\n\n### Development Only Installation\n\nIf you turn off repo logging for any reason in production, you can configure `ecto_dev_logger` to *only* be available\nin development. In your `mix.exs`, restrict the installation to `:dev`:\n\n```elixir\ndef deps do\n  [\n    {:ecto_dev_logger, \"~\u003e 0.10\", only: :dev}\n  ]\nend\n```\n\nIn `MyApp.Application`, an additional function is required:\n\n```elixir\ndefmodule MyApp.Application do\n  @moduledoc \"...\"\n\n  def start(_type, _args) do\n    maybe_install_ecto_dev_logger()\n\n    # ...\n  end\n\n  if Code.ensure_loaded?(Ecto.DevLogger) do\n    defp maybe_install_ecto_dev_logger, do: Ecto.DevLogger.install(MyApp.Repo)\n  else\n    defp maybe_install_ecto_dev_logger, do: :ok\n  end\n\n  # ...\nend\n```\n\n### Format queries\n\nIt is possible to format queries using a `:before_inline_callback` option.\nHere is an example of setup using [pgFormatter](https://github.com/darold/pgFormatter) as an external utility:\n```elixir\ndefmodule MyApp.Application do\n  def start(_type, _args) do\n    Ecto.DevLogger.install(MyApp.Repo, before_inline_callback: \u0026__MODULE__.format_sql_query/1)\n  end\n\n  def format_sql_query(query) do\n    case System.shell(\"echo $SQL_QUERY | pg_format -\", env: [{\"SQL_QUERY\", query}], stderr_to_stdout: true) do\n      {formatted_query, 0} -\u003e String.trim_trailing(formatted_query)\n      _ -\u003e query\n    end\n  end\nend\n```\n\n### Running tests\n\nYou need to run a local postgres server for the tests to interact with. This is one way to do it: \n\n```console\n~$ docker run -p5432:5432 --rm --name ecto_dev_logger_postgres -e POSTGRES_PASSWORD=postgres -d postgres\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuelen%2Fecto_dev_logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuelen%2Fecto_dev_logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuelen%2Fecto_dev_logger/lists"}