fuelen / ecto_dev_logger

An alternative logger for Ecto queries
Apache License 2.0
147 stars 14 forks source link

Installing for subsequent repositories silently fails after first repo install #10

Closed sh41 closed 2 years ago

sh41 commented 2 years ago

Hi again,

We use two repositories, and when we try to install for both of them it silently fails on the second one. I think this can be solved by adding the telemetry_prefix to the handler_id in the call to :telemetry.attach/4.

  @doc """
  Attaches `telemetry_handler/4` to application.
  """
  @spec install(repo_module :: module()) :: :ok
  def install(repo_module) when is_atom(repo_module) do
    config = repo_module.config()

    if config[:log] == false do
      :telemetry.attach(
        ["ecto.dev_logger"] ++ config[:telemetry_prefix],
        config[:telemetry_prefix] ++ [:query],
        &__MODULE__.telemetry_handler/4,
        nil
      )
    else
      :ok
    end
  end

I also changed the if statement so that any response from the call to :telemetry.attach/4 doesn't get swallowed.

Happy to submit this as a PR if you agree that this makes sense? Also happy for anyone else to do this or solve in any other way :-)

fuelen commented 2 years ago

Hey,

yes, it totally makes sense. Happy to accept a PR :)